Trade counter does not work

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #211712 quote
    Peli
    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
    PeterSt
    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
    PeterSt
    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
    robertogozzi
    Moderator
    Master

    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
    Peli
    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
    Nicolas
    Keymaster
    Master

    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.

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 Nicolas
3 years ago.

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