Australian (ASX) Stock Market Forum

Amibroker query

Joined
28 December 2018
Posts
18
Reactions
4
Hi

Im using AFL to test out a simple strategy and noticed an issue that i cant seem to get my head around after using all the other forums. It is something small and silly from myside !

/* Condition MA VaR */
EMA50 = EMA(C,50);

//Buy Conditions
b_maCond = Cross(O,EMA50) AND Cross(C,EMA50);


//Sell Conditions
s_maCond = Cross(EMA50,O) AND Cross(EMA50,C);

//Execute buy and sell signals
Buy = b_maCond ;
Sell = s_maCond;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell, Buy);

Filter = Buy OR SELL;

It a simple MA cross which identifies when the:
a. open and close are above EMA50 for a buy, and
b. the open and close are above EMA50 for a sell.

It uses Exrem to make sure signals are not repeated.

The issue i am having is that it is missing an obvious signal, marked in Red circle, as there was a previous sell and price rose above the EMA50.

Any thoughts ?

upload_2020-8-29_15-45-26.png

p.s. Looking further back on the chart some more signals are also missing:

upload_2020-8-29_15-54-54.png

Missing signals for 1,2,3 as marked

Thanks
 
Hi

Im using AFL to test out a simple strategy and noticed an issue that i cant seem to get my head around after using all the other forums. It is something small and silly from myside !

/* Condition MA VaR */
EMA50 = EMA(C,50);

//Buy Conditions
b_maCond = Cross(O,EMA50) AND Cross(C,EMA50);


//Sell Conditions
s_maCond = Cross(EMA50,O) AND Cross(EMA50,C);

//Execute buy and sell signals
Buy = b_maCond ;
Sell = s_maCond;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell, Buy);

Filter = Buy OR SELL;

It a simple MA cross which identifies when the:
a. open and close are above EMA50 for a buy, and
b. the open and close are above EMA50 for a sell.

It uses Exrem to make sure signals are not repeated.

The issue i am having is that it is missing an obvious signal, marked in Red circle, as there was a previous sell and price rose above the EMA50.

Any thoughts ?

View attachment 108405

p.s. Looking further back on the chart some more signals are also missing:

View attachment 108406

Missing signals for 1,2,3 as marked

Thanks

Hi @Pervaz

Try substituting the code below for your BUY and SELL conditions as I think it will solve your problem.

/* Condition MA VaR */
EMA50 = EMA(C,50);

//Buy Conditions
b_maCond = O>EMA50 AND C>EMA50;

//Sell Conditions
s_maCond = O<EMA50 AND C<EMA50;

Cheers,
Rob
 
Hi Rob

Thanks for that. I was reading up on Cross function and decided to use that (obviously without thinking things thru !!!)

Another quick question please:
I have added Exrem and from my understanding it will produce an arrow if the condition for a buy is true. It will not show another arrow until i get a short condition which is true.

However if i have 2 (or more buy conditions) for a buy it doesnt allow the 2nd buy arrow

using the above example :

/* Condition MA VaR */
EMA50 = EMA(C,50);

//Buy Conditions
b_maCond1 = O>EMA50 AND C>EMA50;
b_maCond2 = O>EMA50 AND C>EMA50 AND C>EMA(C,60);

In the above chart the b_maCond1 is true so an arrow is plotted. However if in the next candle the b_maCond2 is true I would like an arrow to be plotted there as well (even if no sell arrow appeared between the 2 bars)

I am using Exrem(buy, sell) to remove additional arrow

Thanks
 
Hi Rob

Thanks for that. I was reading up on Cross function and decided to use that (obviously without thinking things thru !!!)

Another quick question please:
I have added Exrem and from my understanding it will produce an arrow if the condition for a buy is true. It will not show another arrow until i get a short condition which is true.

However if i have 2 (or more buy conditions) for a buy it doesnt allow the 2nd buy arrow

using the above example :

/* Condition MA VaR */
EMA50 = EMA(C,50);

//Buy Conditions
b_maCond1 = O>EMA50 AND C>EMA50;
b_maCond2 = O>EMA50 AND C>EMA50 AND C>EMA(C,60);

In the above chart the b_maCond1 is true so an arrow is plotted. However if in the next candle the b_maCond2 is true I would like an arrow to be plotted there as well (even if no sell arrow appeared between the 2 bars)

I am using Exrem(buy, sell) to remove additional arrow

Thanks

Hi Pervaz,

If you would like to see every instant that either of your BUY conditions are met then I would suggest you create an indicator to attach to your charts.

The above suggestion will not impact on the Exrem function.

Cheers,
Rob
 
However if i have 2 (or more buy conditions) for a buy it doesnt allow the 2nd buy arrow

@Pervaz if you want to add to your position ( scale in ) then you should read the following from the help file and modify to suit ( add your cond2 instead of percent profit)

https://www.amibroker.com/guide/h_pyramid.html


Code:
Example 3: increasing position when profit generated by trade without pyramiding
becomes greater than 5% and decreasing position when loss is greater than -5%

// percent equity change threshold when pyramiding is performed
PyramidThreshold = 5;

// regular trading rules (no pyramiding)
Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );

e = Equity(1); // generate equity without pyramiding effect

PcntProfit = 100 * ( e - ValueWhen( Buy, e ) )/ValueWhen( Buy, e );

InTrade = Flip( Buy, Sell );

// ExRem is used here to ensure that scaling-in/out occurs
// only once since trade entry
DoScaleIn = ExRem( InTrade AND PcntProfit > PyramidThreshold, Sell );
DoScaleOut = ExRem( InTrade AND PcntProfit < -PyramidThreshold, Sell );

// modify rules to handle pyramiding
Buy = Buy + sigScaleIn * DoScaleIn + sigScaleOut * DoScaleOut;

PositionSize = IIf( DoScaleOut, 500, 1000 ); // enter and scale-in size $1000, scale-out size: $500
 
Top