Enter position only once for a level

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #232319 quote
    ashehzi
    Participant
    Average

    Hi,

    I want to trade a level only once and do not want to enter the trade same level twice. But below code isn’t working:

    RTHoperate = (TIME > 142000 AND TIME < 203000) // GMT+1

    if time < 143000 then
    spread = 2
    else
    spread = 1
    endif

    MyLongPrice = round(max(myBarLower, myBarUpper))
    distance = abs(myBarHigh – myBarLow)

    if NOT ONMARKET and RTHoperate and close > MyLongPrice then  and (MyLongPrice <> tradeprice[1]) then

    SET STOP PLOSS distance + spread
    set target pprofit distance*20
    endif

    Above code (if no market …) keep rentering the same location.

    2nd question: If i want to go long using the same myLongPrice twice, what protection I can put in the code?

    Regards

    Ash

    #232345 quote
    robertogozzi
    Moderator
    Master

    You can use the previous entry price exactly, but the two prices are unlikely to be identical, even to the decimal point!
    This example divides the price by 100 (but you can change it to 50 or 10, etc…), in this way it is easy for the price of the new entry to be in the same range as the previous one and therefore the entry is not made:

    DEFPARAM CUMULATEORDERS = False
    
    ONCE myDivisor  = 100
    ONCE EntryLevel = 0
    
    myLONGconditions  = close CROSSES OVER  Average[20,0](close)
    mySHORTconditions = close CROSSES UNDER Average[20,0](close)
    
    CurrentLevel = round(close / myDivisor,0)
    
    IF Not OnMarket AND CurrentLevel <> EntryLevel THEN
       IF myLONGconditions THEN
          BUY 1 Contract AT MARKET
          EntryLevel = round(close / myDivisor,0)
       ELSIF mySHORTconditions THEN
          SELLSHORT 1 Contract AT MARKET
          EntryLevel = round(close / myDivisor,0)
       ENDIF
    ENDIF
    SET STOP   pLOSS   100
    SET TARGET pPROFIT 200
    graphonprice CurrentLevel * myDivisor coloured("Blue")
    graph myLONGconditions  coloured("Blue")
    graph mySHORTconditions coloured("Red")
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Enter position only once for a level


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ashehzi @ashehzi Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
1 year, 9 months ago.

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