Hello
I am trying to open one trade for a short term strategy and another one for a long term strategy.
I thought that when doing a doLong, the description would be like the id of the trade so later you could close a specific trade using doSell.
That is not the case. So if I do two doLongs, later via doSell they will not be treated as separate trades. I am posting the logic of the code for what I am trying to do
marketIsLong = isMarketLong();
longTradeOpen = isLongTradeOpen();
shortTradeOpen = isShortTradeOpen();
//Finds out if there is an open short term trade. If there is, verifies if exit conditions
if(marketIsLong && longTradeOpen){
lowerShortChannelValue = lowerShortChannel.getValue(-1);
lowerMediumChannelValue = lowerMediumChannel.getValue(-1);
currentLowValue = low(0);
//Verifies if stop was hit
shortTermTradeStopHit = wasStopHit(currentLowValue, shortTermTradeStop);
longTermTradeStopHit = wasStopHit(currentLowValue, longTermTradeStop);
if(shortTermTradeOpen && shortTermTradeStopHit){
Strategy.doSell(shortTermTrade, Strategy.STOP, Strategy.THISBAR, shortTermTradeSize, shortTermTradeStop);
setNewEquity(shortTermTradeStop);
shortTermTradeOpen = false;
debugPrintln("Stop: " + shortTermTradeStop + " Size: " + shortTermTradeSize);
debugPrintln("Short term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
}
else if(longTermTradeOpen && longTermTradeStopHit){
Strategy.doSell(longTermTrade, Strategy.STOP, Strategy.THISBAR, longTermTradeSize, longTermTradeStop);
setNewEquity(longTermTradeStop);
longTermTradeOpen = false;
debugPrintln("Stop: " + longTermTradeStop + " Size: " + longTermTradeSize);
debugPrintln("Long term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
}//Verifies if exit was hit. The conditions accept breaks above entry price
else{
shortTermTradeValidExit = wasValidExitHit(currentLowValue, lowerShortChannelValue);
longTermTradeValidExit = wasValidExitHit(currentLowValue, lowerMediumChannelValue);
if(shortTermTradeOpen && shortTermTradeValidExit){
debugPrintln("Valid exit. Current: " + currentLowValue + " historic: " + lowerShortChannelValue);
debugPrintln("Short term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
shortTermTradeExit = getExitPrice(lowerShortChannelValue);
Strategy.doSell(shortTermTrade, Strategy.STOP, Strategy.THISBAR, shortTermTradeSize, shortTermTradeExit);
shortTermTradeOpen = false;
debugPrintln("Exit: " + shortTermTradeExit + " Size: " + shortTermTradeSize);
setNewEquity(shortTermTradeExit);
}
if(longTermTradeOpen && longTermTradeValidExit){
debugPrintln("Valid exit. Current: " + currentLowValue + " historic: " + lowerMediumChannelValue);
debugPrintln("Long term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
longTermTradeExit = getExitPrice(lowerMediumChannelValue);
Strategy.doSell(longTermTrade, Strategy.STOP, Strategy.THISBAR, longTermTradeSize, longTermTradeExit);
longTermTradeOpen = false;
debugPrintln("Exit: " + longTermTradeExit + " Size: " + longTermTradeSize);
setNewEquity(longTermTradeExit);
}
}
}
//
//Finds out if there is a short or long term trading signal
//Long
if(marketIsLong){
upperMediumChannelValue = upperMediumChannel.getValue(-1);
upperLongChannelValue = upperLongChannel.getValue(-1);
currentHighValue = high(0);
if(!shortTermTradeOpen)
{
if(currentHighValue > upperMediumChannelValue){
shortTermTradeEntry = getEntryPrice(upperMediumChannelValue);
//shortTermTradeSize = getTradingSize(atrValue);
shortTermTradeStop = getShortTermTradeStop(atrValue);
Strategy.doLong(shortTermTrade, Strategy.STOP, Strategy.THISBAR, shortTermTradeSize, shortTermTradeEntry);
shortTermTradeOpen = true;
debugPrintln("Entry: " + shortTermTradeEntry + " Stop: " + shortTermTradeStop + " Size: " + shortTermTradeSize);
debugPrintln("Short term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
}
}
else if(!longTermTradeOpen)
{
if(currentHighValue > upperLongChannelValue){
longTermTradeEntry = getEntryPrice(upperLongChannelValue);
//shortTermTradeSize = getTradingSize(atrValue);
longTermTradeStop = getLongTermTradeStop(atrValue);
Strategy.doLong(longTermTrade, Strategy.STOP, Strategy.THISBAR, longTermTradeSize, longTermTradeEntry);
longTermTradeOpen = true;
debugPrintln("Entry: " + longTermTradeEntry + " Stop: " + longTermTradeStop + " Size: " + longTermTradeSize);
debugPrintln("Long term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
}
}
}
Treating both as a single trade and just adding won't do it because each one has a separate stop and exit conditions.
Treating them as two different studies won't do because I am planning to open the long term trade depending on the short term trade
Would referencing the strategy object be an alternative?
I am using eSignal OnDemand 11.2
Any help will be greatly appreciated
Thanks
I am trying to open one trade for a short term strategy and another one for a long term strategy.
I thought that when doing a doLong, the description would be like the id of the trade so later you could close a specific trade using doSell.
That is not the case. So if I do two doLongs, later via doSell they will not be treated as separate trades. I am posting the logic of the code for what I am trying to do
marketIsLong = isMarketLong();
longTradeOpen = isLongTradeOpen();
shortTradeOpen = isShortTradeOpen();
//Finds out if there is an open short term trade. If there is, verifies if exit conditions
if(marketIsLong && longTradeOpen){
lowerShortChannelValue = lowerShortChannel.getValue(-1);
lowerMediumChannelValue = lowerMediumChannel.getValue(-1);
currentLowValue = low(0);
//Verifies if stop was hit
shortTermTradeStopHit = wasStopHit(currentLowValue, shortTermTradeStop);
longTermTradeStopHit = wasStopHit(currentLowValue, longTermTradeStop);
if(shortTermTradeOpen && shortTermTradeStopHit){
Strategy.doSell(shortTermTrade, Strategy.STOP, Strategy.THISBAR, shortTermTradeSize, shortTermTradeStop);
setNewEquity(shortTermTradeStop);
shortTermTradeOpen = false;
debugPrintln("Stop: " + shortTermTradeStop + " Size: " + shortTermTradeSize);
debugPrintln("Short term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
}
else if(longTermTradeOpen && longTermTradeStopHit){
Strategy.doSell(longTermTrade, Strategy.STOP, Strategy.THISBAR, longTermTradeSize, longTermTradeStop);
setNewEquity(longTermTradeStop);
longTermTradeOpen = false;
debugPrintln("Stop: " + longTermTradeStop + " Size: " + longTermTradeSize);
debugPrintln("Long term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
}//Verifies if exit was hit. The conditions accept breaks above entry price
else{
shortTermTradeValidExit = wasValidExitHit(currentLowValue, lowerShortChannelValue);
longTermTradeValidExit = wasValidExitHit(currentLowValue, lowerMediumChannelValue);
if(shortTermTradeOpen && shortTermTradeValidExit){
debugPrintln("Valid exit. Current: " + currentLowValue + " historic: " + lowerShortChannelValue);
debugPrintln("Short term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
shortTermTradeExit = getExitPrice(lowerShortChannelValue);
Strategy.doSell(shortTermTrade, Strategy.STOP, Strategy.THISBAR, shortTermTradeSize, shortTermTradeExit);
shortTermTradeOpen = false;
debugPrintln("Exit: " + shortTermTradeExit + " Size: " + shortTermTradeSize);
setNewEquity(shortTermTradeExit);
}
if(longTermTradeOpen && longTermTradeValidExit){
debugPrintln("Valid exit. Current: " + currentLowValue + " historic: " + lowerMediumChannelValue);
debugPrintln("Long term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
longTermTradeExit = getExitPrice(lowerMediumChannelValue);
Strategy.doSell(longTermTrade, Strategy.STOP, Strategy.THISBAR, longTermTradeSize, longTermTradeExit);
longTermTradeOpen = false;
debugPrintln("Exit: " + longTermTradeExit + " Size: " + longTermTradeSize);
setNewEquity(longTermTradeExit);
}
}
}
//
//Finds out if there is a short or long term trading signal
//Long
if(marketIsLong){
upperMediumChannelValue = upperMediumChannel.getValue(-1);
upperLongChannelValue = upperLongChannel.getValue(-1);
currentHighValue = high(0);
if(!shortTermTradeOpen)
{
if(currentHighValue > upperMediumChannelValue){
shortTermTradeEntry = getEntryPrice(upperMediumChannelValue);
//shortTermTradeSize = getTradingSize(atrValue);
shortTermTradeStop = getShortTermTradeStop(atrValue);
Strategy.doLong(shortTermTrade, Strategy.STOP, Strategy.THISBAR, shortTermTradeSize, shortTermTradeEntry);
shortTermTradeOpen = true;
debugPrintln("Entry: " + shortTermTradeEntry + " Stop: " + shortTermTradeStop + " Size: " + shortTermTradeSize);
debugPrintln("Short term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
}
}
else if(!longTermTradeOpen)
{
if(currentHighValue > upperLongChannelValue){
longTermTradeEntry = getEntryPrice(upperLongChannelValue);
//shortTermTradeSize = getTradingSize(atrValue);
longTermTradeStop = getLongTermTradeStop(atrValue);
Strategy.doLong(longTermTrade, Strategy.STOP, Strategy.THISBAR, longTermTradeSize, longTermTradeEntry);
longTermTradeOpen = true;
debugPrintln("Entry: " + longTermTradeEntry + " Stop: " + longTermTradeStop + " Size: " + longTermTradeSize);
debugPrintln("Long term trade. Date " + getDay() + "/" + getMonth() + "/" + getYear());
}
}
}
Treating both as a single trade and just adding won't do it because each one has a separate stop and exit conditions.
Treating them as two different studies won't do because I am planning to open the long term trade depending on the short term trade
Would referencing the strategy object be an alternative?
I am using eSignal OnDemand 11.2
Any help will be greatly appreciated
Thanks