how to set breakeven to price of entry

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #238407 quote
    Vicke1990Vicke1990
    Participant
    New

    Hi, I want to write a code so that the breakeven is equal to the price the position was bought for. The system buys 2 contracts initially and sells one after X number of pips, I want the breakeven of the second contract to be set at the entryprice + 2 pips so the 2nd contract can follow a trailing stop instead.

    When I try with:

    if size = 1 then 
    breakevenLevel = entryPrice + PointsToKeep * pipsize Pvalue = breakevenLevel + 2 * pipsize
    It sells the 2nd contract based on where to first sell of the 1st contract took place. I want it to be based on the initial postion instead. I´ve also tried with tradeprice (1) instead of  entryprice  but that seems to refer to the previous latest trade of selling 1 contract instead of the initial price when I bought the position. anyone have any idea on how I can solve this? With kind regards, Victor    

     

    #238410 quote
    robertogozzirobertogozzi
    Moderator
    Legend
    First you have to store the Entry Price on the first entry bar (which is when it’s OnMarket, but it wasn’t the prior bar). Then SET the stop whenever you have reduced the position size:
    IF OnMarket AND Not OnMarket[1] THEN
       EntryLevel     = Tradeprice
       BreakEvenLevel = EntryLevel + (PointsToKeep * pipsize)
    ENDIF
    IF abs(CountOfPosition) < abs(CountOfPosition)[1] then
       SET STOP PRICE BreakEvenLevel
    ENDIF
    Iván González 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

how to set breakeven to price of entry


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vicke1990 @vicke1990 Participant
Summary

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

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