Hi,
I was hoping someone could shed some light as still learning the coding on here. If i I wanted to set a target of the price touching the moving average line, how would I code this?
Thank you
JSParticipant
Senior
Hi,
S1 = Average[Period](Close)
Set Target Price S1
Just a follow up question; how do I do partial closure?
For example two different close positions based on two different moving averages. I have the below code but not sure how to add that
1*atr closes when it reaches 50 moving average
and then the remaining (1*atr) closes when price touches 100 moving average
also, if i wanted to bring the stop loss up to breakeven when it touches for example the 50 moving average, how could i code this?
Any help would be much much appreciated
atr= averagetruerange[12](close)
ma1=average[50]
ma2=average[100]
IF Bullish0 THEN
buy (200/(2*atr)) perpoint AT MARKET
set stop loss (2*atr)
set target price (ma1)
ENDIF
for Breakeven you can maybe look at this page it will help you, and about selling at 2 level
for selling at 2 level of price maybe you can use 2 IF condition and Sell 1 shares when the condition it met
to close partially an order, nice example from Roberto: https://www.prorealcode.com/topic/replacing-tp-with-partial-close/#post-194694
to put order at breakeven (and many other possibilites) with these new instructions: New trading instructions: better management of your orders!
Hi, just wanted to follow up – based on the above formula – with targeting the moving average as a target price, it seems to execute at the moving average value directly correlating with opening candle of the trade. Is it possible to have the target price move with the moving average so its dynamic. So if the todays candle price touches the moving average it closes at that point. With the formula above, it doesnt seem to close, only when the price hits the initial moving average value that was calculated when the trade first opened. Its a bit difficult to explain – hope this makes sense.
Swap lines 8 and 9, so that set target price (ma1) is the last line, i.e. outside the conditionl block IF…ENDIF and will ALWAYS be executed, not just at entry time.
Be warned that ma1 might be lower than the prior candle, thus exiting at a lower price than originally set.