help with limited time exposure to market

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #173266 quote
    MishapMishap
    Participant
    Junior

    Hi Guys,

    I am looking to code some type of scalping, limited time exposure to market (5mins on a 5 second chart) the below code appears to be correct to me but when i run it the max time with it being a loss is still open. is there something wrong with the code?

    note i am running the SL code from forums as well & have a sell for TP & loss.

    any help is appreciated,

    //trailing stop function
    trailingstart = 3.5 //trailing will start @trailinstart points profit
    trailingstep = 1 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    extrapip=2
    if ONMARKET and barindex-tradeindex(1) > 60 and close > (tradeprice(1)+extrapip*pipsize) then
    sell at market
    endif
    
    extrapip1=2
    if ONMARKET and barindex-tradeindex(1) > 60 and close < (tradeprice(1)-extrapip1*pipsize) then
    sell at market
    endif
    
    #173267 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Lines 40-48 should read:

    extrapip=2
    if LongONMARKET and barindex-tradeindex(1) > 60 and close > (tradeprice(1)+extrapip*pipsize) then
       sell at market
    endif
     
    extrapip1=2
    if ShortONMARKET and barindex-tradeindex(1) > 60 and close < (tradeprice(1)-extrapip1*pipsize) then
       Exitshort at market
    endif

    Your trailing stop is so tight that I am afraid it works only when backtesting.

    It doesn’t account for the minimum distance required by IG.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

help with limited time exposure to market


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mishap @mishap Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzirobertogozzi
5 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/07/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...