Value is change when i was used scroll bar.

#1
Hi,


Please advice me about in my condition I want to keep Close price when I buy for compare Close price when I sell . If Close at sell - Close at buy >= 0.2 I will sell.


But I have some problems when I keep close price at position Buy (keep in CloseBuy variable) and show value when I was scroll bar to next day value in variable is change to new Close price and I will scroll bar back to old day it show me same price. How can I resolve this problem?.


This is my script


_SECTION_BEGIN("Plot");


Ema5 = EMA(C,5);
Ma50 = MA(C,50);
Ema5CrossMa50Up = Cross(Ema5,Ma50);

FirstTradeTime = 093000;
LastTradeTime = 154000;
ConditionTimeTrade = TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime ;
IsInTimeTradeBuy = IIf(ConditionTimeTrade,1,0);

LastTradeTimeSell = 155800;
ConditionTimeTradeSell = TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTimeSell ;

IsInTimeTradeSell = IIf(ConditionTimeTradeSell,1,0);

Macd10_25 = MACD(10,25);
Signal10_25 = Signal(10,25,5);
MacdCrossSignalDown10_25 = Cross(Signal10_25,Macd10_25);

ValMacd10_25CrossSignalDown = ValueWhen(Cross(Signal10_25,Macd10_25) AND Macd10_25 > 0 ,Macd10_25);
ValPassMacd10_25CrossSignalDown = Ref(ValueWhen(Cross(Signal10_25,Macd10_25) AND Macd10_25 > 0 ,Macd10_25),-1);
CloseBuyLoop[0] = 0;
CloseBuy = 0;
SellAlready = "N";
DiffPriceClose = 0;

PlotBuy[0] = 0;
PlotSell1[0] = 0;

KeepValue = "N";

for( i = 1; i < BarCount; i++ )
{


if(IsInTimeTradeBuy == 1)
{
/*-------- Buy---------- */



if(Ema5CrossMa50Up == 1)
{
PlotText( "Buy: " + Close , i, L+0.03,colorBlack, colorYellow);
PlotBuy = 1;
if(KeepValue == "N" )
{
CloseBuy= Close;
KeepValue = "Y";
}
}
else
{
PlotBuy = 0;
}




} // if(IsInTimeTradeBuy == 1)

/*-------- Sell ---------- */
if(IsInTimeTradeSell == 1)
{
if(MacdCrossSignalDown10_25 == 1 && Macd10_25 > 0)
{


DiffPriceClose = Close - CloseBuy ;
PlotText( "" + CloseBuy + " : " + Close + " = " + DiffPriceClose , i, H+0.03,colorBlack, colororange);

if(DiffPriceClose >= 0.2)
{

PlotSell1 = 1;
KeepValue = "N";
}
else
{
PlotSell1 = 0;
}
} //if(MacdCrossSignalDown10_25 == 1 && Macd10_25 > 0)


} // if(IsInTimeTradeSell == 1)
else
{

PlotSell1 = 0;

}

}

Buy1 = (PlotBuy == 1) AND ConditionTimeTrade;
Sell1 = (PlotSell1 == 1) ;

Buy = Buy1 ;
Sell = Sell1 ;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),coloryellow,0,L,Offset=-60);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorpink,0,L,Offset=90);

_SECTION_END();
 

Similar threads