Simple Coding Help - No Promise.

I have discovered a very weird problem today.

Fortunately, it seems that I have already solved it but both the problem and solution have nevertheless left me puzzled and it seems grossly unfair to keep you people out enjoying your weekends while I am busy pulling my hair out! :mad: :p

Just before you start dissecting, I have to admit that even though I may have solved the problem, I neither understand the problem nor the solution.

I have a custom AFL in which I added usual four lines to clear out all of the excess signals. But, that was not good enough in this AFL! Lots of entry signals kept repeating. See the first image.

As you can see in the image one, there are no cover signals between two consecutive Shorts signals.

Code:
[FONT="Courier New"]
Buy   = ExRem(Buy, Sell);
Sell  = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
[/FONT]
Code:
[FONT="Courier New"]
Buy   = ExRem(Buy, Sell);
Sell  = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);

LongMode = Flip(Buy  , Sell);
ShrtMode = Flip(Short, Cover);

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
Buy   = ExRem(Buy, Sell);    // duplicate required again
Sell  = ExRem(Sell, Buy);    //  ...
Short = ExRem(Short, Cover); // ...
Cover = ExRem(Cover, Short); // ...
[/FONT]
Second version of the code does solve the problem (extra arrows do disappear) and if I comment out the second set of duplicate ExRems, the duplicate arrows do reappear.

Short and Buy show down arrow and up arrow respectively.
Sell and Cover show down triangle and up triangle respectively.

IMAGE ONE WITH DUPLICATE ARROWS highlighted and second set of ExRem code is commented out


IMAGE TWO WITH DUPLICATE ARROWS gone and second set of ExRem code is not commented out!
 

trash

Well-Known Member
I have discovered a very weird problem today.

Fortunately, it seems that I have already solved it but both the problem and solution have nevertheless left me puzzled and it seems grossly unfair to keep you people out enjoying your weekends while I am busy pulling my hair out! :mad: :p

Just before you start dissecting, I have to admit that even though I may have solved the problem, I neither understand the problem nor the solution.

I have a custom AFL in which I added usual four lines to clear out all of the excess signals. But, that was not good enough in this AFL! Lots of entry signals kept repeating. See the first image.

As you can see in the image one, there are no cover signals between two consecutive Shorts signals.

Code:
[FONT="Courier New"]
Buy   = ExRem(Buy, Sell);
Sell  = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
[/FONT]
Code:
[FONT="Courier New"]
Buy   = ExRem(Buy, Sell);
Sell  = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);

LongMode = Flip(Buy  , Sell);
ShrtMode = Flip(Short, Cover);

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
Buy   = ExRem(Buy, Sell);    // duplicate required again
Sell  = ExRem(Sell, Buy);    //  ...
Short = ExRem(Short, Cover); // ...
Cover = ExRem(Cover, Short); // ...
[/FONT]
Second version of the code does solve the problem (extra arrows do disappear) and if I comment out the second set of duplicate ExRems, the duplicate arrows do reappear.

Short and Buy show down arrow and up arrow respectively.
Sell and Cover show down triangle and up triangle respectively.


There is no ExRem required for TrailStop.

 
Last edited:
Sirs.
Does the ExRem function in a AFL ,
Code:
Short= ExRem(Short,Cover);
remove the excess Occurences only Visually & in BackTesting ?, And it has no effect on other pieces of codes in the AFL ? -->
like it has no effect on
Code:
SRngPrft= ShortPrice-C;
? Bcos "SRngPrft" takes a new "ShortPrice" whenever & wherever there is an Excess "SHORT Signal" wud hve occured (even when the excess "SHORT Signal" is NOT VISIBLE on the CHART or BACKTESTING Report).
Pls Guide to clear the Confusion and to overcome this issue.
Thank U All
Rgrds
--ShiraJ--
K, Got it,
Code:
Short= ExRem(Short,Cover);
, to Be placed before
Code:
SRngPrft= ShortPrice-C;
,
So now hve a new problem coz, my "Cover" can not Be defined without defining "SRngPrft", so as a temp measure, did as follows,
Code:
Cover4=SomeHarmlessButUnNecessaryRule;
Short= ExRem(Short,Cover4);
SRngPrft= ShortPrice-C;
Sirs, Pls suggest an Alternative.
Thank U All,
Rgrds
--ShiraJ--
 
There is no ExRem required for TrailStop.

Trash

My question was not about the trailing stop. Yes, one can certainly write the AFL without ExRem and I have done that in another AFLs but that approach had some problems in this particular AFL's case and therefore cannot be used.

My query was strictly about having to write ExRem two times and as it is seems, the source of the problem is related to the actual definition of Buy, Sell, Short and Cover.

I have finally figured out the problem and hence why the duplication worked and here is small attempt for the explanation.:cool:

In this particular AFL's case, conditions used to exit out of trade are very loosely defined and hence exits keep getting triggered on far too many candles. Commenting all ExRems results in entire chart getting flooded with red and blue triangles.

Need for duplicate ExRem goes away if I simply reorder the lines. i.e. ExRem of the Cover has to be done before the ExRem of Short; The ExRem of Sell must precede the ExRem of Buy.

----------------------------------------------------------------------

@shirajroz

Effect of ExRem is upon all statements that are written after the ExRem line. So, If the back-testing code is after the ExRem, it will be affected.

Code:
Cover4=SomeHarmlessButUnNecessaryRule;

[B]Short= ExRem(Short,Cover4);
Cover = ExRem(Cover4, Short);[/B]

ShortPrice = ValueWhen(Short [B]OR SomeOtherRule[/B], Close);

SRngPrft= ShortPrice - C;
 
Last edited:
@shirajroz

Effect of ExRem is upon all statements that are written after the ExRem line. So, If the back-testing code is after the ExRem, it will be affected.

Code:
Cover4=SomeHarmlessButUnNecessaryRule;

[B]Short= ExRem(Short,Cover4);
Cover = ExRem(Cover4, Short);[/B]

ShortPrice = ValueWhen(Short [B]OR SomeOtherRule[/B], Close);

SRngPrft= ShortPrice - C;
Thank U MasterMindJi,
My bad (and also Majboori as the fulfledged "COVER" cud come only later)

Thanks n Rgrds
--ShiraJ--

P.S. > Looks like only we two r pulling our Hair out (in mycase, Scalp too :confused:) ) during this weekend despite ur wicked ,wicked attempt 2 keep 'em busy :)
 

trash

Well-Known Member
Trash

My question was not about the trailing stop. Yes, one can certainly write the AFL without ExRem and I have done that in another AFLs but that approach had some problems in this particular AFL's case and therefore cannot be used.

My query was strictly about having to write ExRem two times and as it is seems, the source of the problem is related to the actual definition of Buy, Sell, Short and Cover.

I have finally figured out the problem and hence why the duplication worked and here is small attempt for the explanation.:cool:

In this particular AFL's case, conditions used to exit out of trade are very loosely defined and hence exits keep getting triggered on far too many candles. Commenting all ExRems results in entire chart getting flooded with red and blue triangles.

Need for duplicate ExRem goes away if I simply reorder the lines. i.e. ExRem of the Cover has to be done before the ExRem of Short; The ExRem of Sell must precede the ExRem of Buy.
Why do you post a picture showing some trail stop then and some sequential two times ExRem out of context (without preceding simple code example)? I have never required two, three, four, ... times exrem anywhere. Anyway if properly done there is no need for ExRem in trail code or multi ExRem in other codes. I would recommend to send your formula to AB support and they will surely tell you what is wrong in there.

Besides Exrem is not required in Analysis backtest/optimization at all as backtester (default one -> backtestregular mode) takes care of excessive signals itself. You would need Exrem if you want to remove excessive signals in indicator, scan, exploration.
 

jallanankit

Well-Known Member
HOW TO KEEP THE BUY CANDLE CONSTANT ONCE IT APPEARED..


PLS CHECK THE FOLLOWING CODE in post #3389..


Prob is..

ONCE THE BUY/SHORT APPEARS, IT KEEPS MOVING TILL THE TIME FURTHER NEW HIGHS/NEW LOWS ARE MADE..
PLs try copying the code in Ami and my prob statement will be easier to understand!!
 
Last edited:

jallanankit

Well-Known Member
Thank u for the correction.. Hope this is fine..

Thanks shirajroz

Pls look after the continuous changing buy/short arrows in the code attached..

Will delete that code from the post!!

Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) )));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();




H1 = TimeFrameGetPrice("H", inDaily); // Today's high
L1 = TimeFrameGetPrice("L", inDaily); // Today's low
Plot(H1, "",colorBrightGreen,styleDashed);
Plot(L1, "",colorDarkRed,styleDashed);

Buy = High >= Ref(H1,-1);
Short = Low <= Ref(L1 ,-1) ;

Sell =  Short;
Cover =  Buy;

Buy=ExRem(Buy,Short);
Short=ExRem(Short,Buy);



PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-25);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-35); 
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-30);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=25);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=35); 
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-30);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorRed, 0, L, Offset=-15);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorGold, 0,L, Offset=-15);
 

Similar threads