New position for a strategy.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #142241 quote
    Fran55Fran55
    Participant
    Veteran

    Just one more question:

    In the strategy there can be a maximum of 2 positions.
    After a first position, buy another position if the same conditions as the first position are met.
    Or, buy another position, if the price falls 1% from the first position.

    #142298 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Not tested:

    DEFPARAM CumulateOrders = true
    IF Not OnMarket THEN
       PriceFall  = 0
       EntryPrice = 0
    ELSE
       PriceFall  = (close <= (EntryPrice * 0.99))
    ENDIF
    AddPosition = abs(CountOfPosition) < 2
    IF (MyConditions OR PriceFall) AND AddPosition AND Not ShortOnMarket THEN
       BUY 1 CONTRACT AT MARKET
       IF abs(CountOfPosition) = 0 THEN
          EntryPrice = close
       ENDIF
    ENDIF
    #142299 quote
    Fran55Fran55
    Participant
    Veteran

    Thanks Grahal!

    But there is a problem … I can’t get it to work the way I want.

    In the strategy there can be a maximum of 2 positions.
    After a first position, buy another position if the price falls 1% from the first position.

    The strategy with your code buys the two positions when the same conditions are met.
    What I want is that I only buy the first position with conditions, and the second position if the price falls 1% from the first position.


    The first photo is what I have so far.
    The second photo shows that it always buys the second position when the conditions of the first position are met, since it always buys the second position a few pips after the first position.
    Screenshot_1-1.png Screenshot_1-1.png Screenshot_2-1.png Screenshot_2-1.png
    #142305 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    That’s what you asked

    “After a first position, buy another position if the same conditions as the first position are met.
    Or, buy another position, if the price falls 1% from the first position.”

    I am not GraHal.

    If you don’t want to buy the second position with the same conditions as the first one, change line 9:

    IF ((MyConditions AND (Countofposition = 0)) OR PriceFall) AND AddPosition AND Not ShortOnMarket THEN
    #142310 quote
    Fran55Fran55
    Participant
    Veteran

    Jjhajjjaaa!!!

     

    Sorry Roberto!

    #142327 quote
    Fran55Fran55
    Participant
    Veteran
    #142332 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Post your code if you want help about it, instead of general examples.

Viewing 7 posts - 1 through 7 (of 7 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

New position for a strategy.


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Fran55 @fran55 Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by robertogozzirobertogozzi
6 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/21/2020
Status: Active
Attachments: 3 files
ProRealCode ProRealCode
Loading...