Help for modify long position for short position

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #73616 quote
    onoisukaaa
    Participant
    Junior

    Hello i need some help for modify existing algo made by Wilko.

    Curent algo take only Long postion and i want modify for taking both.

    Original code (only buy ):

    ShortRSI = RSI[2](close)
    LongRSI = RSI[30](close) //1 month RSI
    MA = Average[22,0](close) //1 month moving average of close
    Slope = MA/MA[1]-1 //Slope of 1 month moving average
    
    MaxPos = 1 //Set to tolerated maximum position
    
    LongEntry = CountOfLongShares < MaxPos //Buy until MaxPos reached
    LongEntry = LongEntry AND ShortRSI < 15 //Buy when RSI2 below 15
    LongEntry = LongEntry AND LongRSI > 50 //Filter for 1month RSI above 50
    LongEntry = LongEntry AND Slope > 0 //Filter for positive slope of MA22
    
    LongExit = LongOnMarket
    LongExit = LongExit AND ShortRSI > 60 //Exit position when RSI2 above 60
    
    
    // Conditions to enter long positions
    IF LongEntry THEN
    BUY 2 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    IF LongExit THEN
    SELL AT MARKET
    ENDIF

    My (bad )modification for short :

    ShortRSI = RSI[2](close)
    LongRSI = RSI[30](close) //1 month RSI
    MA = Average[22,0](close) //1 month moving average of close
    Slope = MA/MA[1]-1 //Slope of 1 month moving average
    
    MaxPos = 2 //Set to tolerated maximum position
    
    ShortEntry = CountOfShortShares < MaxPos //Buy until MaxPos reached
    ShortEntry = ShortEntry AND ShortRSI > 60 //Short when RSI2 above 60
    ShortEntry = ShortEntry AND LongRSI < 50 //Filter for 1month RSI below 50
    ShortEntry = ShortEntry AND Slope > 0 //Filter for positive slope of MA22
    
    ShortExit = ShortOnMarket
    ShortExit = ShortExit AND ShortRSI < 15 //Exit position when RSI2 below 15
    
    
    // Conditions to enter short positions
    IF ShortEntry THEN
    SELL 2 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    IF ShortExit THEN
    BUY AT MARKET
    ENDIF

    With my modification when i backtest i have zero results

    Thanks for your helps

    #73619 quote
    Vonasi
    Moderator
    Master

    At first look the BUY and SELL instructions that you use are the wrong ones. You need to use SELLSHORT and EXITSHORT for short position entry and exit. BUY and SELL are for long positions only.

    // Conditions to enter short positions
    IF ShortEntry THEN
    SellShort 2 CONTRACTS AT MARKET
    ENDIF
     
    // Conditions to exit short positions
    IF ShortExit THEN
    ExitShort AT MARKET
    ENDIF
    #73644 quote
    onoisukaaa
    Participant
    Junior
    #73656 quote
    GraHal
    Participant
    Master

    Where you have the exclamation marks use the term mySellShort and myExitShort.

    Sorry for jumping in Vonasi, just keeping the momentum going! 🙂

    #73674 quote
    Vonasi
    Moderator
    Master

    Sorry for jumping in Vonasi

    Jump in all you like GraHal. I’ve been out enjoying myself sailing in the rain. Rain in Greece in June! …..and Trump says there is no global warming!

    GraHal thanked this post
    #73675 quote
    Vonasi
    Moderator
    Master

    Your short code was fine. It is just that:

    BUY // Used to open a long position.
    SELL // Used to close a long position
    SELLSHORT // Used to open a short position
    EXITSHORT // Used to close a short position

    So your code would be:

    ShortRSI = RSI[2](close)
    LongRSI = RSI[30](close) //1 month RSI
    MA = Average[22,0](close) //1 month moving average of close
    Slope = MA/MA[1]-1 //Slope of 1 month moving average
     
    MaxPos = 2 //Set to tolerated maximum position
     
    ShortEntry = CountOfShortShares < MaxPos //Buy until MaxPos reached
    ShortEntry = ShortEntry AND ShortRSI > 60 //Short when RSI2 above 60
    ShortEntry = ShortEntry AND LongRSI < 50 //Filter for 1month RSI below 50
    ShortEntry = ShortEntry AND Slope > 0 //Filter for positive slope of MA22
     
    ShortExit = ShortOnMarket
    ShortExit = ShortExit AND ShortRSI < 15 //Exit position when RSI2 below 15
     
     
    // Conditions to enter short positions
    IF ShortEntry THEN
    SELLSHORT 2 CONTRACTS AT MARKET
    ENDIF
     
    // Conditions to exit short positions
    IF ShortExit THEN
    EXITSHORT AT MARKET
    ENDIF
    #73679 quote
    onoisukaaa
    Participant
    Junior

    Thanks a lot guys !!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Help for modify long position for short position


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
onoisukaaa @onoisukaaa Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by onoisukaaa
7 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/19/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...