Hi. I want to create a simple program for automatic trading that creates small scalping trades using 15 minute and 5 minute charts (5 minute is the default).
I am experimenting with different conditions to open the trade but as an example lets say this is a long trade and the opening condition is that MACDline (12,26,9) crosses over 50 on the 5 minute chart. And the RSI(14) must be below 50 on the 15 minute chart
On the 15 minute chart I have created 2 bands using the ATR. The upper band is the close + the ATR(14) and the lower band is the close – the ATR(14).
When the trade is opened on the close of the 5 minute bar I want the profit target to be the upper ATR band on the 15 minute chart at the time the trade is opened, and the stop loss to be the lower ATR band on the 15 minute chart at the time the trade is opened.
Can you help me to code this please?
Your question is ProOrder related and not a platform support issue so I have moved your post. Posting in the correct forum will have the best chance of getting a solution and will save us moderators a lot of time moving posts around all day!
Please try to post in the correct forum with future posts. 🙂
You mean MACDline (12,26,9) crosses over 0 ?
This the code:
TIMEFRAME(15 minutes, updateonclose)
MyRsi = Rsi[14](close)
MyAtr = AverageTrueRange[14](close)
UpperATR = close + MyAtr
LowerATR = close - MyAtr
TIMEFRAME(default) //5 minutes
MyMacd = MACDline[12,26,9](close)
MyConditions = (MyMacd CROSSES OVER 0) AND (MyRsi < 50)
IF MyConditions AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
Tp = ABS(UpperATR - close)
Sl = ABS(close - LowerATR)
SET TARGET PROFIT Tp
SET STOP LOSS Sl
ENDIF
When computing SL and TP I used ABS(() to make sure it’s not a negative number, because UPDATEONCLOSE at line 1 makes TF15 values older than TF5 so a sudden surge on the default TF might cause, even temporarily, a closing price higher/lower than it was when TF15 closed.
If you remove UPDATEONCLOSE then you can also remove ABS() but values on TF15 will be the current ones when the TF5 closes, not when TF15 closed last time.
If you want to try you can even launch the strategy from a 3-minute or 1-minute TF, since 15 is a multiple of 5, 3 and 1 (not 2).
Even I can understand this one! 🙂 Thank you Paulon and Roberto.
Results attached for 1 Hour and 3 mins default otherwise unchanged from Roberto code above.
Version 1.4 with Shorts.
If you improve then please post on here so we can all share.
//https://www.prorealcode.com/topic/multi-timeframe-scalp-code-question/
DEFPARAM CUMULATEORDERS = False
Trade = Time > 060000 and Time < 205500
TIMEFRAME(1 Hour)
MyRsi = Rsi[8](close)
MyAtr = AverageTrueRange[2](close)
UpperATR = close + MyAtr
LowerATR = close - MyAtr
TIMEFRAME(default) //3 minutes
MyMacd = MACDline[12,26,9](close)
MyConditionL = (MyMacd CROSSES OVER 0) AND (MyRsi < 50) and Trade //50
IF MyConditionL and not onmarket THEN
BUY 1 CONTRACT AT MARKET
TpL = (UpperATR - close)
SlL = (close - LowerATR)
SET TARGET PPROFIT TpL
SET STOP PLOSS SlL
ENDIF
MyConditionS = (MyMacd CROSSES UNDER 0) AND (MyRsi > 50) and Trade //50
IF MyConditionS and not onmarket THEN
SellShort 1 CONTRACT AT MARKET
SLS = (UpperATR - close)
TPS = (close - LowerATR)
SET TARGET PPROFIT TpS
SET STOP PLOSS SlS
ENDIF
//GRAPH UpperATR - close
//GRAPH close - LowerATR
//GRAPH TPL
//GRAPH TPS
//