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)..
``````_SECTION_BEGIN("TestStrategy");

//Get details of the hourly candle
TimeFrameSet(in15Minute);

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

//Get details of the daily ATR
TimeFrameSet(inDaily);

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

TimeFrameRestore();

//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

sellConditionForDay = 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).
SellCon = Cross(currCandleLow, DCConditionForShort);

sellCondition = SellCon  AND Sum( SellCon, barsince ) <= sellConditionForDay;

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

ShortTriggerPrice = sellCandleLow - 0.01*sellCandleLow;

sellTriggerValue = IIf( currCandleLow <= ShortTriggerPrice, True,False);

ShortPrice = IIf(sellTriggerValue, ShortTriggerPrice, 0);

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

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

signalColor = IIf(buySignal, colorGreen, IIf(sellSignal, colorRed, colorLightGrey));

}

_SECTION_END();
``````

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)..
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", ""));
``````

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