Trade counter does not work

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #211712 quote
    PeliPeli
    Participant
    New

    Hello

    I am trying to bild a counter to determine when the bad trades are made.

    I started to evaluate wich day of the week, but its count wrong.

    Here is an snippet from the code

    if buycondition then
    buy positionsize contract at market
    tradecounterall=tradecounterall+1
    Trigger = 1 //Trigger that a new position are open so you evalute the last one
    endif

     

    Once TradeCounterall =0
    Once Trigger = 0
    Once BadMondag=0
    Once BadTisdag=0
    Once BadOnsdag=0
    Once BadTorsdag=0
    Once BadFredag=0

    if Trigger = 1 then
    if PositionPerf(1)< 0.0 then //If the last position whas bad count the day that trade whas made
    if currentday =1 then
    BadMondag=BadMondag+1
    elsif currentday=2 then
    BadTisdag=BadTisdag+1
    elsif currentday=3 then
    BadOnsdag=BadOnsdag+1
    elsif Currentday=4 then
    BadTorsdag=BadTorsdag+1
    elsif Currentday=5 then
    BadFredag=BadFredag+1
    endif

    currentday=Currentdayofweek //Set th current day for next trade
    Trigger=0
    endif

     

    graphonprice tradecounterall coloured(0,0,255,255) as “tradecounter”
    graphonprice BadMondag coloured(0,0,255,255) as “Mondag”
    graphonprice BadTisdag coloured(0,0,255,255) as “Tisdag”
    graphonprice BadOnsdag coloured(0,0,255,255) as “Onsdag”
    graphonprice BadTorsdag coloured(0,0,255,255) as “Torsdag”
    graphonprice BadFredag coloured(0,0,255,255) as “Fredag”

     

    In the backtest I do, the calculator in the grah, for example tradecounterall, says that there have been 215 trades, and if I add upp all the bad days, it might be say 65pcs. But when I read the same values from the Detailed report it shows other numbers. Let say Totalt: 150, Losing:50.

    What is wrong or can anyone suggest another way to do this?

    #211722 quote
    PeterStPeterSt
    Participant
    Master

    Hi there Peli,

    Remove the Once before Trigger. Put the line Trigger = 0 to the top of the code.

    Good luck ! -Peter

    #211723 quote
    PeterStPeterSt
    Participant
    Master

    No, my answer won’t help.

    Can you see the Graphonprice showing the bad trades as expected ? If Yes then what …

    #211725 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    PositionPerf returns the temporary gain or loss candle by candle.

    To tell if a trade gained or lost you have to compare the current StrategyProfit with that of the prior candle.

    #211734 quote
    PeliPeli
    Participant
    New

    Thanks for the replys.

    I use PositionPerf(1) so it should count the profit from the last ended trade. No temporary gain.

    However, I realized that i have the setting defparam cumulateorders = false.

    So even if there was no trade taking place when the buconditions were valid, the counter counted up.

    So I changed to

    if buycondition then
    buy positionsize contract at market
    if not shortonmarket and not longonmarket then
    Trigger = 1 //Trigger that a new position are open so you evalute the last one
    tradecounterall=tradecounterall+1
    endif
    endif

    its works not perfect but good enough.

    But I realy wanted to write something like

    If cumulateorders=false and not shortonmarket and not longonmarket then

    …….

    elsif cumulateorders=true then

    …….

    endif

     

    But the program does not accept it. I don´t know how to write to take the cumulateorders settings into account?

    #211778 quote
    NicolasNicolas
    Keymaster
    Legend

    If you allow cumulating of orders, it means that you can be on market with more than 1 order at the same time, so just create a variable that count the quantity of BUY and quantity of  SELLSHORT in a row, and reset that variables when you invert the trade direction.

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

Trade counter does not work


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Peli @peli Participant
Summary

This topic contains 5 replies,
has 4 voices, and was last updated by NicolasNicolas
3 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/18/2023
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...