Help please to code a One Shot Trading System

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #193833 quote
    Berwick
    Participant
    New
    1.   If +20 points from 8:00am price, open Long.
    2.  If  – 20 points from 8:00am price, open Short.
    3. For Long & Short trades, SL = -20 TP = +96.
    4. If +10 in profit,  move stop to -10, close 50 % of pos size.
    5. If +40 in profit, move stop to +16  and close 50% of remaining pos size.
    6. If +44 in profit, start trailing stop to trail by + 20, then move by +1 for each successive +1 rise.
    7. Trade exits either by TS or the TP (+96).
    8. System then Quits.
    #194062 quote
    robertogozzi
    Moderator
    Master

    There you go:

    ONCE LotSize   = 4             //lots to be traded
    ONCE Offset    = 20 * PipSize  //offset fom 8am price
    ONCE Distance  = 7             //Distance rquired by the broker for pending oifers (to be checked with the broker)
    ONCE PriceAt8  = 0
    ONCE ExitPrice = 0
    IF Not OnMarket AND OnMarket[1] THEN
       QUIT
    ENDIF
    IF IntraDayBarIndex = 0 THEN
       PriceAt8 = 0
    ENDIF
    IF OpenTime = 080000 THEN
       PriceAt8 = close
    ENDIF
    IF OnMarket AND Not OnMarket[1] THEN
       Entry = TradePrice
    ENDIF
    IF Not OnMarket AND PriceAt8 > 0 THEN
       IF close >= (PriceAt8 + Offset) THEN
          BUY LotSize Contract at Market
       ELSIF close <= (PriceAt8 - Offset) THEN
          SELLSHORT LotSize Contract at Market
       ENDIF
       ExitPrice = 0
       TrailFlag = 0
       TrailBase = 20
       SET TARGET pPROFIT 96
       SET STOP   pLOSS   20
    ENDIF
    IF OnMarket THEN
       MyProfit  = PositionPrice * PositionPerf / PipSize
       Positions = abs(CountOfPosition)
       IF MyProfit >= 44 THEN
          IF LongOnMarket THEN
             ExitPrice = Entry + TrailBase * PipSize
          ELSE
             ExitPrice = Entry - TrailBase * PipSize
          ENDIF
          TrailBase = TrailBase + 1
       ELSIF MyProfit > 40 AND TrailFlag = 1 THEN
          TrailFlag = 2
          IF LongOnMarket THEN
             ExitPrice = Entry + 16 * PipSize
             SELL (Positions / 2) CONTRACTS at Market
          ELSE
             ExitPrice = Entry - 16 * PipSize
                EXITSHORT (Positions / 2) CONTRACTS at Market
          ENDIF
       ELSIF MyProfit >= 10 AND TrailFlag = 0 THEN
          TrailFlag = 1
          IF LongOnMarket THEN
             ExitPrice = Entry - 10 * PipSize
             SELL (Positions / 2) CONTRACTS at Market
          ELSE
             ExitPrice = Entry + 10 * PipSize
             EXITSHORT (Positions / 2) CONTRACTS at Market
          ENDIF
       ENDIF
    IF ExitPrice > 0 THEN
       IF LongOnMarket THEN
          IF close >= (ExitPrice + Distance) THEN
             SELL AT ExitPrice STOP
          ELSIF close <= (ExitPrice - Distance) THEN
             SELL AT ExitPrice LIMIT
          ELSE
             //SELL AT Market
          ENDIF
       ELSE
          IF close <= (ExitPrice - Distance) THEN
             EXITSHORT AT ExitPrice STOP
          ELSIF close >= (ExitPrice + Distance) THEN
             EXITSHORT AT ExitPrice LIMIT
          ELSE
             //EXITSHORT AT Market
          ENDIF
       ENDIF
       ENDIF
    ENDIF
    //graphonprice Entry
    //graphonprice ExitPrice coloured(255,0,0,255)
    //graph        MyProfit

    I added a DISTANCE as required by the broker (the correct value is to be checked with the broker)  for pending orders. If an order is placed at an incorrect price, the oredr is rejected and the strategy stopped (in both demo and real, not in backtest, of course).

    As to the DISTANCE I added two commented lines (thus ignored) to exit at MARKET if the distance is not enough. If you wat to use those two lines, simply remove the leading slashes.

    To disable the distance, set it to 0.

    GraHal, PeterSt, Berwick, Midlanddave and rrmp12 thanked this post
    #194074 quote
    Berwick
    Participant
    New

    Thank you very much Roberto, much appreciated.

    rrmp12 thanked this post
    #194081 quote
    GraHal
    Participant
    Master

    Roberto is so very kind helping us all out, coding our ideas!

    Let us know how you get on Monday please Berwick.  I’m going to give it a go also! 🙂

    robertogozzi thanked this post
    #194084 quote
    robertogozzi
    Moderator
    Master

    A 20-pip SL is so tight that it almost always is hit and the strategy is stopped immediately.

    To test it, I used a 100-pip SL and commented out the QUIT instruction.

    GraHal thanked this post
    #194090 quote
    Berwick
    Participant
    New

    Roberto is so very kind helping us all out, coding our ideas!

    Let us know how you get on Monday please Berwick. I’m going to give it a go also! 🙂

    GraHal,  please be aware that this is not the entry strategy that I use, my initial request was for a trade manager and it is this part of the code that I am really interested in. Monday may be a quiet day on the markets as it is Memorial Day in the US.

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

Help please to code a One Shot Trading System


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Berwick @berwick Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by Berwick
3 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/25/2022
Status: Active
Attachments: No files
Logo Logo
Loading...