Auto Trading Entry/Exit

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

    Hello,

    So I tried my first Trading System on Demo, its on a 2min chart, it opens an Entry and then at the same time exit.

    I’m sure its not a fault with the software, its me.

    #173972 quote
    robertogozzi
    Moderator
    Master

    Great you could find out how to make it work!

    Is there anything you missed to ask?

    SpreadBetMH thanked this post
    #173976 quote
    PeterSt
    Participant
    Master

    it opens an Entry and then at the same time exit.

    Just show us your code and we probably will be able to see why it Exits right away.
    You best insert your code by means of the “Add PRT Code” button, but on my screen that button has disappeared.


    @Roberto
    , it should be there, see attachment. So I am probably blind today.

    image_2021-07-22_090154.png image_2021-07-22_090154.png
    #173978 quote
    PeterSt
    Participant
    Master

    PS: And after posting my message, the button is suddenly back ? (see attachment).
    Apologies I did not make a screenshot of the “Visual” tab when it was missing.

    image_2021-07-22_090347.png image_2021-07-22_090347.png
    #173981 quote
    robertogozzi
    Moderator
    Master

    There’s a bug that Nicolas is investigating.

    It often appears again by refreshing the page.

    In the meantime you can use the TEXT tab, which works.

    SpreadBetMH thanked this post
    #174053 quote
    SpreadBetMH
    Participant
    Average

    Hi there, this is the code

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    // The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the “FLATBEFORE” time.
    DEFPARAM FLATBEFORE = 080000
    // Cancel all pending orders and close all positions at the “FLATAFTER” time
    DEFPARAM FLATAFTER = 235500

    // Prevents the system from creating new orders to enter the market or increase position size before the specified time
    noEntryBeforeTime = 080000
    timeEnterBefore = time >= noEntryBeforeTime

    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 163000
    timeEnterAfter = time < noEntryAfterTime

    // Prevents the system from placing new orders on specified days of the week
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0

    // Conditions to enter long positions
    indicator1 = Average[11](close)
    indicator2 = Average[47](close)
    c1 = (indicator1 CROSSES OVER indicator2)

    IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1000 PERPOINT AT MARKET
    ENDIF

    // Conditions to exit long positions
    indicator3 = Average[47](close)
    indicator4 = Average[11](close)
    c2 = (indicator3 CROSSES OVER indicator4)

    IF c2 THEN
    SELL AT MARKET
    ENDIF

    // Conditions to enter short positions
    indicator5 = Average[47](close)
    indicator6 = Average[11](close)
    c3 = (indicator5 CROSSES OVER indicator6)

    IF c3 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    SELLSHORT 1000 PERPOINT AT MARKET
    ENDIF

    // Conditions to exit short positions
    indicator7 = Average[11](close)
    indicator8 = Average[47](close)
    c4 = (indicator7 CROSSES OVER indicator8)

    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF

    // Stops and targets
    SET STOP pLOSS 35
    SET TARGET pPROFIT 179

    #174054 quote
    PeterSt
    Participant
    Master
    IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
      BUY 1000 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = Average[47](close)
    indicator4 = Average[11](close)
    c2 = (indicator3 CROSSES OVER indicator4)
    
    IF c2 THEN
      SELL AT MARKET
    ENDIF

     

    I did not try to follow your conditions really, in order to see that both conditions can be True and thus the first thing what may happen is the BUY and the subsequent next may be the SELL (this will probably happen in the next bar (call of the program) or else both cancel each other anyway).

    What lacks is lines like

    If not OnMarket then
      // Do your Buy or Sell thing.
    Endif
    
    // or :
    
    If not LongOnMarket then
      // Do your Buy thing.
    Endif
    
    // or :
    
    If ShortOnMarket then
      // Do your Exit Short thing.
    Endif
    

    It is not per se so that a Sell without being OnMarket will imply a Short in code, though under conditions this may happen (like my “cancel out each other” example). It is merely about the logic you need to apply because else you will Buy (or Exit) two times.

    Good luck now !

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

Auto Trading Entry/Exit


Platform Support: Charts, Data & Broker Setup

New Reply
Author
Summary

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

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 07/21/2021
Status: Active
Attachments: 2 files
Logo Logo
Loading...