StopLoss at lowest price

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #109197 quote
    carlo__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__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.
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

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__carlo__
7 years ago.

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