StopLoss at lowest price

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

    Hello Community

     

    For educational purpose, i am trying to code a script where the lowest[x](low) in previous bars could acts as a strategy stop loss

    Additionally, the distance between tradeprice and stop loss price would be the Target Profit. I coded the following but seems it doesnt’t do the job.

    IF myconditons AND NOT ONMARKET THEN
    BUY 1 CONTRACTS AT MARKET
    LowestPrice = lowest[12](low)
    ENDIF
    
    IF ONMARKET THEN
    if (close < LowestPrice) then
    SELL AT MARKET
    ENDIF
    ENDIF
    
    IF ONMARKET THEN
    TargetProfit = TradePrice - LowestPrice
    SET TARGET PPROFIT TargetProfit
    ENDIF

    I would be grateful if you can explain me why this code doesn’t work properly, cause i can run up my learning curve.

    Thank you!

    #109198 quote
    carlo__
    Participant
    Average

    Ok it seems to be fixed. I added the NOT ONMARKET condition (edited the previous post) in the first row and it does the job. Sorry for double-posting but my internet connection is a bit weak today.

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

StopLoss at lowest price


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
carlo__ @carlo__ Participant
Summary

This topic contains 1 reply,
has 1 voice, and was last updated by carlo__
6 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/03/2019
Status: Active
Attachments: No files
Logo Logo
Loading...