Reset ValueWhen array at the end of day

Hi There,

I am working on the below Exploration and running this on 15 Minute Time frame. The logic for buy is

  1. Current candle should break the Don Chain Channel 50 candle.
  2. Need to get the high price of the breakout candle
  3. My Buy Signal will be when the price moves above (breakoutCandleHigh+ breakoutCandleHigh*001)..

//Get details of the hourly candle

DonchianUpper =HHV(Ref(H,0),50);
DonchianLower = LLV(Ref(L,0),50);

//Get details of the daily ATR 

atrValue = Ref(ATR(14),-1);


//Need to Expand the array details set in hourly and daily 
DonchianUpperExpanded = TimeFrameExpand(DonchianUpper,in15Minute);
DonchianLowerExpanded = TimeFrameExpand(DonchianLower,in15Minute);

//NextCandleHighExpanded = TimeFrameGetPrice("H",in15Minute,0);
atrValueExpanded = TimeFrameExpand(atrValue,inDaily);
currCandleHigh = TimeFrameGetPrice("H",in15Minute,0);
currCandleLow = TimeFrameGetPrice("L",in15Minute,0);

dn = Day();

newday = dn != Ref(dn,-1);  //check if new day or not
starttime = TimeNum();
barsince = BarsSince( newDay) +1;

sellConditionForDay = 1;
buyConditionForDay = 1; 

//set the DC values constant for the day.. 
 DCconditionForEntry = ValueWhen(newday,DonchianUpperExpanded);
 DCConditionForShort = ValueWhen(newday,DonchianLowerExpanded);

//check if the current candle high crosses constant DC values for day. (same for condition for low also). 
 buyCon = Cross(currCandleHigh,  DCconditionForEntry);
 SellCon = Cross(currCandleLow, DCConditionForShort);
 //consider 1st buy condition, if we have multiple buy condition.. 
 buyCondition =  buyCon AND Sum( buyCon, barsince ) <= buyConditionForDay ;
 sellCondition = SellCon  AND Sum( SellCon, barsince ) <= sellConditionForDay;

//Get 1st buy condition candle's High/low... (need to reset this at the endof day)..  
 buyCandleHigh = ValueWhen(buyCondition, currCandleHigh);
 sellCandleLow =ValueWhen(sellCondition, currCandleLow);

 BuyTriggerPrice = buyCandleHigh + 0.01*buyCandleHigh;
 ShortTriggerPrice = sellCandleLow - 0.01*sellCandleLow;

buyTriggerValue = IIf( currCandleHigh >= BuyTriggerPrice, True,False) ;
sellTriggerValue = IIf( currCandleLow <= ShortTriggerPrice, True,False);

BuyPrice = IIf(buyTriggerValue, BuyTriggerPrice,0);
ShortPrice = IIf(sellTriggerValue, ShortTriggerPrice, 0);


if(Status("Action") == actionExplore ){

buySignal = buyTriggerValue AND Sum( buyTriggerValue, barsince ) <= buyConditionForDay ;
sellSignal = sellTriggerValue  AND Sum( sellTriggerValue, barsince ) <= sellConditionForDay;

Filter = 1;//buySignal || sellSignal; 


signalStatus = Writeif(buySignal, "Buy", WriteIf(sellSignal, "Sell", ""));
signalColor = IIf(buySignal, colorGreen, IIf(sellSignal, colorRed, colorLightGrey));
AddTextColumn(signalStatus, "ColorCode", 1, colorWhite, signalColor);
AddColumn( IIf( buySignal, 'B', 'S' ), "Signal", formatChar );

AddColumn(atrValueExpanded, "ATR14");

AddColumn(buyCandleHigh, "TriggerCandleHigh");
AddColumn(sellCandleLow, "TriggerCandleLow");

AddColumn(BuyPrice, "BuyPrice");
AddColumn(ShortPrice, "ShortPrice");



I am not sure, how to reset the value of buyCandleHigh at the end of the day in the below code..

//Get 1st buy condition candle's High/low... (need to reset this at the endof day)..  
 buyCandleHigh = ValueWhen(buyCondition, currCandleHigh);
 sellCandleLow =ValueWhen(sellCondition, currCandleLow);

Please see the result of the exploration, when the date is changed, the triggerCandleHigh value is constant. Need to reset this to 0 at the start of the day, appreciate if someone can guide me here.

From quick look at your code you seem to be doing same mistakes as described here and here. So if you are after profitl/loss target stops use ApplyStop or looping.

And this one

signalStatus = Writeif(buySignal, "Buy", WriteIf(sellSignal, "Sell", ""));
AddTextColumn(signalStatus, "ColorCode", 1, colorWhite, signalColor);

will not output array of string. Use AddMultitextColumn of AB 6.20 instead (for historical text output).

And if you want to reset at end of day then use something like below one for exit signal.

NOTE: this is just example.

session_endtime = 155500;

Sell = Sell OR TimeNum() >= session_endtime; 

Also see KB article here where Cross is used instead.

1 Like

@fxshrat, thanks for your suggestion. I had managed to follow this link, to loop through the contents and remove excessive signals.

Really appreciate your help offline also. Thank you again.