Set Buy Price for the next day after buy signal

Hi, I'm new to amibroker..
please someone to advise how i can set buyprice on the next day after get buy signal, and enter the trade if price cross up the previous high when get the buy signal? thanks.

//Candle		= 
BP = ((O-L)/(H-L + 1e-9 ) >= (2/3) AND C >= O) OR ((C-L)/(H-L + 1e-9 ) >= (2/3) AND C < O);

MS = Ref(C,-2) < Ref(O,-2) AND Ref(O,-1) < Ref(C,-2) AND Ref(O,-1) < O AND Ref(C,-1) < Ref(C,-2) AND Ref(C,-1) < O AND C > (Ref(O,-2)+Ref(C,-2))/2 AND 
abs(Ref(C,-1)-Ref(O,-1)) < abs(Ref(C,2)-Ref(O,-2))/2 AND abs(Ref(C,-1)-Ref(O,-1)) < abs(C-O)/2;

//Trading Option
SetOption("InitialEquity", 10000 );
SetTradeDelays( 0, 0, 0, 0);
RoundLotSize = 1; 
SetOption("MaxOpenPositions",5);

Range = ATR(20);

RiskPerShare =  1 * Range ;
ApplyStop( stopTypeLoss, stopModePoint, RiskPerShare, True );
PositionRisk = 1;
PctSize =  PositionRisk * BuyPrice / RiskPerShare;
SetPositionSize( PctSize, spsPercentOfEquity );



Buy = (BP OR MS) AND MA(C,50) > MA(C,150) AND C > MA(C,200); 
Sell = MA(C,50) < MA(C,150);


Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

> Blockquote

1 Like

You should specify ALL the details about the settings of AA windows, not just code.

Assuming you are running Daily TimeFrame,

BuySignal = (BP OR MS) AND MA(C,50) > MA(C,150) AND C > MA(C,200);

/// Buy next day in Daily TF and price crosses above Prev Day High
Buy = Ref( BuySignal, -1) AND Cross( C, Ref( H, -1));

Hi @travick;

BuySignal = (BP OR MS) AND MA(C,50) > MA(C,150) AND C > MA(C,200);

/// Buy next day in Daily TF and price crosses above Prev Day High
Buy = Ref( BuySignal, -1) AND Cross( C, Ref( H, -1));

In line with your above code, if I implement codes as below---is it logically correct?

Buy = Ref (BuySignal,-1) AND Cross( C, Ref( H, -1)); 
Short = Ref (ShortSignal,-1) AND Cross( C, Ref( L, -1));
Sell = Ref (SellSignal,-1) AND Cross( C, Ref( L, -1));
Cover = Ref (CoverSignal,-1) AND Cross( C, Ref( H, -1)); 

Also, can we have the below codes as logically correct for the idea that ---

I want to buy/sell/short/cover at the current candle and current price only if the corresponding signal is generated at the previous candle and the current price is exactly equal to the signal generated price in the previous candle.

Buy = Ref (BuySignal,-1) AND Cross( C, ValueWhen(BuySignal,-1)); 
Short = Ref (ShortSignal,-1) AND Cross( C, ValueWhen(ShortSignal,-1));
Sell = Ref (SellSignal,-1) AND Cross( C, ValueWhen(SellSignal,-1));
Cover = Ref (CoverSignal,-1) AND Cross( C, ValueWhen(CoverSignal,-1)); 

Please guide / help.

The first set of codes are fine.

But in second code you can't enter on current signal candle when you have this code
Buy = Ref (BuySignal,-1)

Can you explain what you are thinking here ?

Buy = . . . Cross( C, ValueWhen(BuySignal,-1));

-1 is not a price Array, how can Close Cross over it?

Thanks @travick for replying.

So, how to implement the below idea:

I want to buy/sell/short/cover at the current candle only when the corresponding signals are generated at the previous candle and the current price in the current candle is crossing the signal generated price of the previous candle, in the appropriate direction .

signal generated price will depend on your signal but if you don't want to unnecessarily complicate things, just use the close price of that bar.
Cross( C, Ref(C, -1)) which you'd have written as Cross( C, ValueWhen( BuySignal, C))

The other problem is, you are expecting next bar to open lower and then CROSS above which is also an issue because what if price never comes back to those levels.

If you have a god system, you'll just be loosing out of trades.

Got it, thanks travick...

You can mark Post #2 as solution if your query is solved,
because this thread seems to flow into other follow ups.

So, does it mean that :

the current price has crossed the close price of the previous candle in which the buy signal occured ?

If yes,then how to code for the Buyprice to do calculations like profit / loss?

Hi wat if we use intraday setting below daily time frame