Moving Averages to prevent unnecessary trades opening

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #181986 quote
    SpreadBetMH
    Participant
    Average

    Hi There,

    I have been looking for code, I have been trying to code a 2 Moving Average as part of my trading system.

    50 Period Moving Average

    200 Period Moving Average

    when the 50 MA has crossed over on top of the 200 MA, then my trading system will only take  buy/long Trades

    and when the 200MA has crossed over on top of the 50, then the trading system will only take Sell/Short Trades

    I am trying to eliminate, the trading system from going against the trend and only taking Buy/Long trades when the market is on the up and Short/Sell trades when the Market is moving down.

    I would like to attach this code into an existing trading system.

    #181989 quote
    robertogozzi
    Moderator
    Master

    There you go;

    Sma50  = average[50,0](close)
    Sma200 = average[200,0](close)
    UPtrend   = Sma50 > Sma200
    DOWNtrend = Sma50 < Sma200
    If MyLongConditions and UPtrend Then
       Buy at Market
    ElsIf MyShortConditions and DOWNtrend Then
       SellShort at Market
    Endif
    SpreadBetMH thanked this post
    #181992 quote
    SpreadBetMH
    Participant
    Average

    Thank you

    Roberto

    #181997 quote
    SpreadBetMH
    Participant
    Average

    Hello again,

    So when I implement the code I get this message coming up:

    The Following variable is undefined: MyLongConditions, MyShortConditions

     

    Thanks again

    #181998 quote
    nonetheless
    Participant
    Master

    MyLongConditions and MyShortConditions will be the existing conditions from the system you are adding this to.

    #181999 quote
    SpreadBetMH
    Participant
    Average
    //EURUSD 1 Hour
    //Buy when RSI crosses over Bollinger Down then Buy 1
    A = RSI[13](Close)
    B = BollingerDown[25](Close)
    C = BollingerUp[25](Close)
    IF A < 3 AND Close < B THEN
    BUY 1 SHARE AT MARKET
    ENDIF
    //When RSI crosses over  close out trade
    Sma50  = average[50,0](close)
    Sma200 = average[200,0](close)
    UPtrend   = Sma50 > Sma200
    DOWNtrend = Sma50 < Sma200
    If MyLongConditions and UPtrend Then
    Buy at Market
    ElsIf MyShortConditions and DOWNtrend Then
    SellShort at Market
    Endif
    
    IF A > 75 AND Close > C THEN
    SELL AT MARKET
    ENDIF
    #182000 quote
    nonetheless
    Participant
    Master
    //EURUSD 1 Hour
    //Buy when RSI crosses over Bollinger Down then Buy 1
    A = RSI[13](Close)
    B = BollingerDown[25](Close)
    C = BollingerUp[25](Close)
    
    //When RSI crosses over  close out trade
    Sma50  = average[50,0](close)
    Sma200 = average[200,0](close)
    UPtrend   = Sma50 > Sma200
    DOWNtrend = Sma50 < Sma200
    IF A < 3 AND Close < B and UPtrend Then
    Buy 1 contract at Market
    
    ElsIf A > 75 AND Close > C and DOWNtrend Then
    SellShort 1 contract at Market
    Endif
     
    
    SpreadBetMH and robertogozzi thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Moving Averages to prevent unnecessary trades opening


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by nonetheless
4 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/21/2021
Status: Active
Attachments: No files
Logo Logo
Loading...