Need help on coding Risk-reward factor

Hello,

I'm failing to formulate a condition on Risk-reward properly. I'm going wrong somewhere. I want to incorporate RRR parameter in order to minimize trading signals, but the filter is not working properly.
Trading signal is very simple: I'm looking for price to simply close above 20EMA, but want to filter signal, as is indicated earlier, using RRR profile (please find a chart attached).

Expert Advisor (I incorporated below formula by editing _Price indicator viz. on default chart)

Buy = Close>EMA(Close,20) AND 0.75*(High-Low)<(HHV(High,20)-High);

Short = Close<EMA(Close,20) AND 0.75*(High-Low)<(Low-LLV(Low,20));

Scanner

Below is the formula I used for Scanning of chart. I modified formula so that signal appears on close of candle.

Buy = Ref(Close,-1)>Ref(EMA(Close,20),-1) 
AND 0.75*(Ref(High,-1)-Ref(Low,-1))<(Ref(HHV(High,20),-1)-Ref(High,-1));

Short = Ref(Close,-1)<Ref(EMA(Close,20),-1)
AND 0.75*(Ref(High,-1)-Ref(Low,-1))<(Ref(Low,-1)-Ref(LLV(Low,20),-1));

RRR parameter
Please help!

1 Like

Piscean,

Since we don’t know what you mean by “the filter is not working properly”, you have a choice. Either take the time to explain it to us in more detail, or use the debugging techniques listed in this site to solve it yourself.

As a (hopefully) helpful suggestion… Try to break down each piece of your filter into smaller quantifiable components and then build them up. When you can see the actual numbers that each piece of your condition generates, you will probably find where you expect a different number, and then you can fix that piece (or your expectation).

Adding columns to an exploration, so you can see the numbers, is what often helps me find my error, or misunderstanding.

Hope this helps.
Snoopy

1 Like

@Piscean I agree with @snoopy.pa30 completely that when your code does not seem to be doing what you had planned, break it into small segments and EXPLORE the calculations. You wrote in your post "Scanner" (in bold capitals no less) but then what you displayed was a Chart?? How easily can you tell what the calculations are from looking at a Chart?

Amibroker actually has a terrific way for you to "scan" or "explore" your code. Below is one possible example (and your code seems to be working to me).

Buy = cover = Close > EMA( Close, 20 ) AND 0.75 * ( High - Low ) < ( HHV( High, 20 ) - High );
BuyCondition = Close > EMA( Close, 20 );
firstFilter = 0.75 * ( High - Low ) < ( HHV( High, 20 ) - High );

Short = Sell = Close < EMA( Close, 20 ) AND 0.75 * ( High - Low ) < ( Low - LLV( Low, 20 ) );
SellCondition = Close < EMA( Close, 20 );
secondFilter = 0.75 * ( High - Low ) < ( Low - LLV( Low, 20 ) );

///  Explore the calculations ///
Filter = 1;
Buy_color1 = IIf( BuyCondition, colorLime, colorDefault );
Buy_color2 = IIf( firstFilter, colorLime, colorDefault );
Buy_color3 = IIf( Buy, colorLime, colorDefault );

SELL_color1 = IIf( SellCondition, colorRose, colorDefault );
SELL_color2 = IIf( secondFilter, colorRose, colorDefault );
SELL_color3 = IIf( Short, colorRose, colorDefault );

AddColumn( Close, "Close" );
AddColumn( BuyCondition, "BuyCondition", 1.0, colorDefault, Buy_color1 );
AddColumn( firstFilter, "firstFilter", 1.0, colorDefault, Buy_color2 );
AddColumn( Buy, "Buy", 1.0, colorDefault, Buy_color3 );

AddColumn( SellCondition, "SellCondition", 1.0, colorDefault, SELL_color1 );
AddColumn( secondFilter, "secondFilter", 1.0, colorDefault, SELL_color2 );
AddColumn( Short, "Short", 1.0, colorDefault, SELL_color3 );

Produces this type of Exploration
image

1 Like

Thank you for help. Am very new to Amibroker. I will try to incorporate whatever being suggested. Will try to do better.
Thank you again.

1 Like