Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Nymphodora), 485 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Catching closing trades #479673
04/17/20 08:18
04/17/20 08:18
Joined: Apr 2020
Posts: 9
D
DanielX Offline OP
Newbie
DanielX  Offline OP
Newbie
D

Joined: Apr 2020
Posts: 9
Hi,

I have a rather simple strategy which I am trying to backtest to understand the Zorro platform.
It basically has a entry-condition and when met it enters a trade using the enterLong-function with a Stop and Profit set. (done in the run() function of course)

So far working as expected and enters new trades when it should, but my question is how I can capture when the Stop or Profit is hit in a bar-cycle.
I know I can use the ThisTrade to get access to the recently entered trade, but how can I find trades that was closed by hitting the Stop or Profit in the same bar-cycle?

Do I have to write my own TradeManagementFunction, do I have to loop through all closed trades, or is there another way?

/Daniel

Re: Catching closing trades [Re: DanielX] #479675
04/17/20 11:09
04/17/20 11:09
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Loop through the closed trades, and check if TradeBarClose is identical to the current bar.

Re: Catching closing trades [Re: DanielX] #479718
04/20/20 09:32
04/20/20 09:32
Joined: Apr 2020
Posts: 9
D
DanielX Offline OP
Newbie
DanielX  Offline OP
Newbie
D

Joined: Apr 2020
Posts: 9
Hi,
thanks, that was kind of easy laugh

However, when trying the following:

for(closed_trades)
if(TradeBarClose == Bar)
printf("\n --- TradePriceOpen: %.2f TradePriceClose: %.2f TradeStopLimit %.2f TradeStopDiff %.2f TradeProfitLimit: %.2f TradeProfit: %.2f",
(var) TradePriceOpen, (var) TradePriceClose, (var) TradeStopLimit, (var) TradeStopDiff, (var) TradeProfitLimit, (var) TradeProfit );

I get the following result:

--- TradePriceOpen: 33.58 TradePriceClose: 31.21 TradeStopLimit 31.22 TradeStopDiff -2.36 TradeProfitLimit: 36.96 TradeProfit: 5.14
--- TradePriceOpen: 30.83 TradePriceClose: 28.52 TradeStopLimit 28.54 TradeStopDiff -2.31 TradeProfitLimit: 33.93 TradeProfit: 2.49
--- TradePriceOpen: 30.62 TradePriceClose: 28.39 TradeStopLimit 28.38 TradeStopDiff -2.25 TradeProfitLimit: 33.67 TradeProfit: 8.00

The TradeProfit looks really strange.
The first trade for example is a loss, but TradeProfit = 5.14
According to the documentation TradeProfit = (TradePriceClose-TradePriceOpen) which isn't true for any of the trades...


/Daniel

Re: Catching closing trades [Re: DanielX] #479721
04/20/20 14:00
04/20/20 14:00
Joined: Apr 2020
Posts: 9
D
DanielX Offline OP
Newbie
DanielX  Offline OP
Newbie
D

Joined: Apr 2020
Posts: 9
Found the problem...
I had incorrect data for the asset in AccountsFix.csv.


So now it looks a bit better when testing.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1