Hi everyone,
maybe my example was not so easy to read. So I searched in the manual and in the chapter Tips&Tricks I find something that should close half the position.
Example from the manual:
...
TRADE* MyTrade = enterlong();
...ThisTrade = MyTrade; // connect trade variables to MyTrade
var MyResult = TradeProfit; // evaluate trade variables
...
exitTrade(MyTrade,0,TradeLots/2); // exit half the trade
For unknown reasons it does not work for me.
Here is my more simple code:
int counter = 0;
TRADE* myTrade;
void run()
{
set(PLOTNOW|LOGFILE);
LookBack = 0;
Fill = 3;
Verbose = 0;
StartDate = 20200101;
EndDate = 20200131;
Slippage = Commission = Spread = 0;
asset("AAPL_EOD");
//Counter
counter ++;
//Entering position
if(counter<2){
Lots = 100;
myTrade = enterLong();
}
//Closing position
if(counter>2){
exitTrade(myTrade, 0, TradeLots/2);
}
}
And here the log file:
Test: partialTakeProfits AAPL_EOD 2020
[AAPL_EOD::L00104] Long 100@73.14 at 15:00:00
[1: Fri 20-01-03 16:00] 0000 +6.00 1/0 (73.20)
Friday 20-01-03 Loss -59.00 ----
[2: Mon 20-01-06 16:00] 0000 +65.00 1/0 (73.79)
Monday 20-01-06 Profit +59.00 ----
[AAPL_EOD::L00104] Sell 100@73.82: +68.00 Bid 73.82
Why does it sell 100 instead of half the position (in this case 50)?