Posted By: jbhunter
Optimize issues - 03/28/20 05:36
I am having some troubles with optimize calls. I have a function below, TradeStrangle, that I would like to optimize some parameters for an option combo. As it is below I am able to optimize with no issues.
However, if there is an option already open, I would prefer to skip all the code in the first IF statement and only run it if the option has been expired.
If I change the if statement to the below. Then It appears it only get trades on the first optimize step. barDate and dateStrangle are both ints of YYYYMMDD. I have printed the values and they are correct. No trades are made on further steps. See log excerpt below.
Any thoughts on how to best only continue with the first IF statement if the option is expired? I would prefer to not use NumOpenTotal < 1 if there are other trades besides the option combo.
However, if there is an option already open, I would prefer to skip all the code in the first IF statement and only run it if the option has been expired.
If I change the if statement to the below. Then It appears it only get trades on the first optimize step. barDate and dateStrangle are both ints of YYYYMMDD. I have printed the values and they are correct. No trades are made on further steps. See log excerpt below.
Code
if (vol > minVol && vol < maxVol && barDate > dateStrangle)
Code
Loop[1] p1 step 1: 50.00 => 104.40 86/ 6 Loop[1] p1 step 2: 55.00 => 0.00 0/ 0 Loop[1] p1 step 3: 60.00 => 0.00 0/ 0 Loop[1] p1 step 4: 65.00 => 0.00 0/ 0 Loop[1] p1 step 5: 70.00 => 0.00 0/ 0 Loop[1] p1 step 6: 75.00 => 0.00 0/ 0
Any thoughts on how to best only continue with the first IF statement if the option is expired? I would prefer to not use NumOpenTotal < 1 if there are other trades besides the option combo.
Code
void TradeStrangle() { var PROB = optimize(90,50,95,5); var days = 7*7;//optimize(6*7,2*7,8*7,7); var maxVol = optimize(0.25,0.10,0.2,0.02); //0.2; var minVol = optimize(0,0,0.10,0.02); if (vol > minVol && vol < maxVol) { if(!contractUpdate(Asset,0,CALL|PUT)) return; var PriceCurrent = Contracts->fUnl; contractCPD(days); var highPrice = cpdv(50+0.5*PROB); //parameter is percent probability var lowPrice = cpdv(50-0.5*PROB); //Find days for contract CONTRACT* c = contractFind(PUT,days,2,6); int date = c->Expiry; var spread = (highPrice-PriceCurrent); var c1s = highPrice; var c2s = highPrice+spread/5; CONTRACT* c1 = contract(CALL,date,c1s); CONTRACT* c2 = contract(PUT,date,c2s); printf("\nStrangle, %i,%i",dateStrangle,barDate); if(NumOpenTotal < 1) // Enter new position { printf(",go"); var fval = (c1->fBid + c2->fBid)*Multiplier; int numContracts = 1; var premium = numContracts*fval; if(combo( c1,-numContracts, c2,-numContracts, 0,0, 0,0)) { MarginCost = 0.15*priceClose()/2; Commission = 0.65/Multiplier; enterLong(comboLeg(1)); enterLong(comboLeg(2)); dateStrangle = date; } } } }