Averaging down/up code is not working

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #120613 quote
    rama
    Participant
    Senior
    //-------------------------------------------------------------------------
    // Main code : buy(1)
    //-------------------------------------------------------------------------
    DEFPARAM FlatBefore = 143500
    
    DEFPARAM FlatAfter = 210000
    
    
    // Conditions to enter short positions
    IF NOT onmarket THEN
    sellshort 4 CONTRACTS AT MARKET
    ENDIF
    nu=12
    nn=20222
    nn1=200
    // Conditions to exit short positions
    if countofposition<=7 and countofposition>=4 then
    IF longonmarket and  close>tradeprice-nu THEN
    sellshort 3 CONTRACTS AT tradeprice-nu stop
    endif
    endif
    if  countofposition<=9 and countofposition>=7 then
    IF longonmarket and  close>tradeprice-nu THEN
    sellshort 2 CONTRACTS AT tradeprice-nu stop
    endif
    endif
    if  countofposition<=10 and countofposition>=9 then
    IF longonmarket and close>tradeprice-nu THEN
    sellshort 1 CONTRACTS AT tradeprice-nu stop
    
    endif
    
    
    
    
    endif
    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
    if onmarket and  (floatingprofit <=-nn or floatingprofit >= nn1) then
    exitshort at market
    
    endif
    

    I want to sell 10 contacts first 4 at market then 3 , 2, 1 at last trade price – nu, this code is not working for shortpostions, where the long position code is working fine where i replaced just close<tradprice+nu then, what is wrong with  this code?

    #120614 quote
    rama
    Participant
    Senior
    //-------------------------------------------------------------------------
    // Main code : buy
    //-------------------------------------------------------------------------
    DEFPARAM FlatBefore = 143500
    
    DEFPARAM FlatAfter = 210000
    
    
    // Conditions to enter short positions
    IF NOT onmarket THEN
    buy 4 CONTRACTS AT MARKET
    ENDIF
    nu=12
    nn=20222
    nn1=200
    // Conditions to exit short positions
    if countofposition<=7 and countofposition>=4 then
    IF longonmarket and  close<tradeprice+nu THEN
    buy 3 CONTRACTS AT tradeprice+nu stop
    endif
    endif
    if  countofposition<=9 and countofposition>=7 then
    IF longonmarket and  close<tradeprice+nu THEN
    buy 2 CONTRACTS AT tradeprice+nu stop
    endif
    endif
    if  countofposition<=10 and countofposition>=9 then
    IF longonmarket and close<tradeprice+nu THEN
    buy 1 CONTRACTS AT tradeprice+nu stop
    
    endif
    
    
    
    
    endif
    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
    if onmarket and  (floatingprofit <=-nn or floatingprofit >= nn1) then
    sell at market
    
    endif
    
    #120616 quote
    Vonasi
    Moderator
    Master

    Change LONGONMARKET to SHORTONMARKET?

    #120617 quote
    Vonasi
    Moderator
    Master

    rama – Please give your topics more meaningful titles otherwise we end up with a forum full of meaningless ‘code is not working’ topics. I have edited your topic title.

    #120618 quote
    GraHal
    Participant
    Master

    You need it as below (If shortonmarket, countofposition <=7 etc    …

    not tested though

    if countofposition<= -7 and countofposition>=-4 then
    IF shortonamrket and  close>tradeprice-nu THEN
    sellshort 3 CONTRACTS AT tradeprice-nu stop
    endif
    #120619 quote
    GraHal
    Participant
    Master

    Yeah it works! 🙂

    CountofPosition of Shorts need a – / minus so – 4, -7 etc

    DEFPARAM FlatBefore = 143500
     
    DEFPARAM FlatAfter = 210000
     
     
    // Conditions to enter short positions
    IF NOT onmarket THEN
    sellshort 4 CONTRACTS AT MARKET
    ENDIF
    nu=12
    nn=20222
    nn1=200
    // Conditions to exit short positions
    if countofposition>= -7 and countofposition<= -4 then
    IF shortonmarket and  close>tradeprice-nu THEN
    sellshort 3 CONTRACTS AT tradeprice-nu stop
    endif
    endif
    if  countofposition>= -9 and countofposition<= -7 then
    IF shortonmarket and  close>tradeprice-nu THEN
    sellshort 2 CONTRACTS AT tradeprice-nu stop
    endif
    endif
    if  countofposition>= -10 and countofposition<= -9 then
    IF shortonmarket and close>tradeprice-nu THEN
    sellshort 1 CONTRACTS AT tradeprice-nu stop
     
    endif
     
     
     
     
    endif
    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
    if onmarket and  (floatingprofit <=-nn or floatingprofit >= nn1) then
    exitshort at market
     
    endif
    
    Rama.jpg Rama.jpg
    #120621 quote
    Vonasi
    Moderator
    Master

    Well spotted GraHal – I didn’t spot that COUNTOFPOSITION was not shown as negative for short positions. You’re getting pretty good at this code analysis!

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

Averaging down/up code is not working


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
rama @rama Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/26/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...