5 registered members (AndrewAMD, ozgur, Ayumi, 2 invisible),
690
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
TradeIsEntry appears to always be False
#471945
03/27/18 18:51
03/27/18 18:51
|
Joined: Sep 2017
Posts: 12
Trading4pips
OP
Newbie
|
OP
Newbie
Joined: Sep 2017
Posts: 12
|
I'm trying to use TradeIsEntry ( http://zorro-project.com/manual/en/trade.htm) in my script. However, I'm finding it's always false, even after trades have been entered into. I've tested this in 1.74 and the beta (1.80.7) I found anther script here: http://www.opserver.de/ubb7/ubbthreads.p...true#Post452443 that uses TradeIsEntry where it appears that TradeIsEntry is also not working. After I've inserted printf statements in the above code (see below), it is showing that TradeIsEntry is always false. How can I properly use TradeIsEntry such that it returns True?
#define H1 (60/BarPeriod)
#define H24 (1440/BarPeriod)
#define W1 (7200/BarPeriod)
int myTMF1() {
if (TradeIsEntry) {
AssetVar[2] += 1;
if (TradeIsLong) AssetVar[3] += 1;
if (TradeIsShort) AssetVar[4] += 1;
printf("A. \nTradeIsEntry: %.5f, AssetVar[2]: %.5f, AssetVar[3]: %.5f, AssetVar[4]: %.5f\n",TradeIsEntry,AssetVar[2],AssetVar[3],AssetVar[4]);
}
return 0;
}
int myTMF() {
if (TradeIsEntry) {AssetVar[2] = AssetVar[2] + 1;
if (TradeIsLong) AssetVar[3] += 1;
if (TradeIsShort) AssetVar[4] += 1;
}
if (TradeIsLong and TradeIsStop and AssetVar[4] < 1){
enterShort(myTMF);
printf("\nB. entershort\n");
printf("\nC. TradeIsEntry: %.5f, AssetVar[2]: %.5f, AssetVar[3]: %.5f, AssetVar[4]: %.5f\n",TradeIsEntry,AssetVar[2],AssetVar[3],AssetVar[4]);
}
return 0;
if (TradeIsShort and TradeIsStop and AssetVar[3] < 1) {
enterLong(myTMF);
printf("\nD. entershort\n");
}
return 0;
return 0;
}
function frameAlign(BOOL Event){
// Let time frame start when Event == true
// f.i. frameAlign(hour() == 0); aligns to midnight
TimeFrame = 1;
vars Num = series(0); // use a series for storing Num between calls
Num[0] = Num[1]+1; // count Num up once per bar
if(!Event)
TimeFrame = 0; // continue current time frame
else {
TimeFrame = -Num[0]; // start a new time frame
Num[0] = 0; // reset the counter
}
}
function run() {
set(TICKS|PARAMETERS|FACTORS|LOGFILE);
Weekend = 3; // don't run TMF at weekend
StartDate = 20140901;
EndDate = 20141231; //preserve 2015 data for OOS testing
BarPeriod = 60;
LookBack = 209;
if (is(INITRUN)) { AssetVar[0] = 0; AssetVar[1] = 0; AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; }
TimeFrame = W1;
frameAlign(dow() == 7 and hour() == 23); //align weekly chart to a UTC open time of Sunday 2200 (note it is 2100 in summer)
vars closeW1 = series(priceClose());
AssetVar[1] = closeW1[0];
TimeFrame = H1;
if (dow() == 7 and hour() == 23) { AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; } //reset to zero at start of each week
int exitDay = 5;
int exitHour = 16;
var entryMultiple = 4;//
Stop = 30 *PIP;
Trail =2 * entryMultiple * ATR(168); // optimize(0.5, 0.25, 3.0, 0.25) * entryMultiple * ATR(168); //
if (AssetVar[2] == 0) {
if (!(dow() == exitDay and hour() >= exitHour)) {
Entry = closeW1[0] + entryMultiple*ATR(168);
if (NumOpenLong == 0) enterLong(myTMF1);
Entry = closeW1[0] - entryMultiple*ATR(168);
if (NumOpenShort == 0) enterShort(myTMF1);
}
}
if (AssetVar[2] > 0) {
if (!(dow() == exitDay and hour() >= exitHour)) {
Entry = closeW1[0];
if (NumOpenLong == 0 and AssetVar[3] < 1) { enterLong(myTMF);}
if (NumOpenShort == 0 and AssetVar[4] < 1) { enterShort(myTMF);}
}
}
if (dow() == exitDay and hour() == exitHour) {exitLong("*"); exitShort("*");}
plot("closeW1", closeW1, MAIN, RED);
}
|
|
|
Re: TradeIsEntry appears to always be False
[Re: Trading4pips]
#471956
03/28/18 16:27
03/28/18 16:27
|
Joined: Apr 2008
Posts: 586 Austria
Petra
Support
|
Support
Joined: Apr 2008
Posts: 586
Austria
|
int tmf() {
if(TradeIsEntry) printf("\nTradeIsEntry!");
return 0;
}
function run() {
Entry = 10*PIP;
if(random() > 0.9)
enterLong(tmf);
if(random() < -0.9)
exitLong();
}
|
|
|
Re: TradeIsEntry appears to always be False
[Re: Sphin]
#471960
03/28/18 19:23
03/28/18 19:23
|
Joined: Sep 2017
Posts: 12
Trading4pips
OP
Newbie
|
OP
Newbie
Joined: Sep 2017
Posts: 12
|
ty @Sphin, TradeIsOpen also didn't work. ty @Petra, the code helped a lot and showed me that the issue in the code I posted above were the printf statements. For those that are interested, here is the above code with the correct printf statements:
#define H1 (60/BarPeriod)
#define H24 (1440/BarPeriod)
#define W1 (7200/BarPeriod)
int myTMF1() {
if (TradeIsEntry) {
AssetVar[2] += 1;
if (TradeIsLong){
AssetVar[3] += 1;
printf("\nA. TradeIsLong & AssetVar[3] is %.2f\n",(var)AssetVar[3]);
}
if (TradeIsShort) {
AssetVar[4] += 1;
printf("\nB. TradeIsShort & AssetVar[4] is %.2f\n",(var)AssetVar[4]);
}
printf("\nC. TradeIsEntry: %.2d, AssetVar[2]: %.2f, AssetVar[3]: %.2f, AssetVar[4]: %.2f\n",TradeIsEntry,(var)AssetVar[2],(var)AssetVar[3],(var)AssetVar[4]);
}
return 0;
}
int myTMF() {
if (TradeIsEntry) {AssetVar[2] = AssetVar[2] + 1;
if (TradeIsLong) AssetVar[3] += 1;
if (TradeIsShort) AssetVar[4] += 1;
}
if (TradeIsLong and TradeIsStop and AssetVar[4] < 1){
enterShort(myTMF);
printf("\nD. entershortn");
printf("\nE. TradeIsEntry: %.2d, AssetVar[2]: %.2f, AssetVar[3]: %.2f, AssetVar[4]: %.2f\n",TradeIsEntry,(var)AssetVar[2],(var)AssetVar[3],(var)AssetVar[4]);
}
return 0;
if (TradeIsShort and TradeIsStop and AssetVar[3] < 1) {
enterLong(myTMF);
printf("\nE. entershort\n");
}
return 0;
return 0;
}
function frameAlign(BOOL Event){
// Let time frame start when Event == true
// f.i. frameAlign(hour() == 0); aligns to midnight
TimeFrame = 1;
vars Num = series(0); // use a series for storing Num between calls
Num[0] = Num[1]+1; // count Num up once per bar
if(!Event)
TimeFrame = 0; // continue current time frame
else {
TimeFrame = -Num[0]; // start a new time frame
Num[0] = 0; // reset the counter
}
}
function run() {
set(TICKS|PARAMETERS|FACTORS|LOGFILE);
Weekend = 3; // don't run TMF at weekend
StartDate = 20140901;
EndDate = 20141231; //preserve 2015 data for OOS testing
BarPeriod = 60;
LookBack = 209;
if (is(INITRUN)) { AssetVar[0] = 0; AssetVar[1] = 0; AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; }
TimeFrame = W1;
frameAlign(dow() == 7 and hour() == 23); //align weekly chart to a UTC open time of Sunday 2200 (note it is 2100 in summer)
vars closeW1 = series(priceClose());
AssetVar[1] = closeW1[0];
TimeFrame = H1;
if (dow() == 7 and hour() == 23) { AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; } //reset to zero at start of each week
int exitDay = 5;
int exitHour = 16;
var entryMultiple = 4;//
Stop = 30 *PIP;
Trail =2 * entryMultiple * ATR(168); // optimize(0.5, 0.25, 3.0, 0.25) * entryMultiple * ATR(168); //
if (AssetVar[2] == 0) {
if (!(dow() == exitDay and hour() >= exitHour)) {
Entry = closeW1[0] + entryMultiple*ATR(168);
if (NumOpenLong == 0) enterLong(myTMF1);
Entry = closeW1[0] - entryMultiple*ATR(168);
if (NumOpenShort == 0) enterShort(myTMF1);
}
}
if (AssetVar[2] > 0) {
if (!(dow() == exitDay and hour() >= exitHour)) {
Entry = closeW1[0];
if (NumOpenLong == 0 and AssetVar[3] < 1) { enterLong(myTMF);}
if (NumOpenShort == 0 and AssetVar[4] < 1) { enterShort(myTMF);}
}
}
if (dow() == exitDay and hour() == exitHour) {exitLong("*"); exitShort("*");}
plot("closeW1", closeW1, MAIN, RED);
}
|
|
|
Re: TradeIsEntry appears to always be False
[Re: Trading4pips]
#471961
03/28/18 19:32
03/28/18 19:32
|
Joined: Sep 2017
Posts: 12
Trading4pips
OP
Newbie
|
OP
Newbie
Joined: Sep 2017
Posts: 12
|
Unfortunately, I still can't resolve the issue with TradeIsEntry in my code. It appears to always be false since the printf statement in the TMF never prints. Here is a snippet of my code. Can anyone review and let me know what I need to change to resolve the issue? Thanks.
/* DISCLAIMERS:
The following code and ideas are for educational purposes only
and is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR,
CONDITIONS OF ANY KIND, either express or implied.
Trading involves substantial risk of loss and is not suitable for all
investors. Past performance is not indicative of future results.
DESCRIPTION: Identify Hi and Low of Open Range and enter into 3 trades
on break of either Hi or Low. Set 1 Stop & 3 Targets for scale outs.
*/
// Define AssetVar to be used in run function & TMF
#define EntryHI AssetVar[0]
#define EntryLO AssetVar[1]
#define Range AssetVar[2]
#define TradesToday AssetVar[3]
#define TradesLong AssetVar[4]
#define TradesShort AssetVar[5]
int tmf() {
// 3 longs / 3 shorts - with 1 Stop & 3 Targets for scale outs
enterLong(0,EntryHI,Range,Range); // (Lots, Entry, Stop, Target)
enterLong(0,EntryHI,Range,Range*2);
enterLong(0,EntryHI,Range,Range*3);
enterShort(0,EntryLO,Range,Range);
enterShort(0,EntryLO,Range,Range*2);
enterShort(0,EntryLO,Range,Range*3);
if (TradeIsEntry) { // ?? Always appears to be false as printf is never printed. ??
printf("\nTMF-A. TradeIsEntry! %.5d\n",TradeIsEntry);
TradesToday += 1;
if (TradeIsLong) {
TradesLong += 1;
printf("\nTMF-B. Trade for %s is Long.\n TradesToday: (%.0f) & TradesLong: (%.0f) s/b 1, while TradesShort: (%.0f) s/b 0\n",Asset,TradesToday,TradesLong,TradesShort);
}
if (TradeIsShort) {
TradesShort += 1;
printf("\nTMF-C. Trade for %s is Short.\n TradesToday: (%.0f) & TradesShort: (%.0f) s/b 1, while TradesLong: (%.0f) s/b 0\n",Asset,TradesToday,TradesShort,TradesLong);
}
}
return 0;
}
function run() {
set(TICKS|LOGFILE); //|RISKLIMIT|PLOTNOW);
BarPeriod = 30; // 1 Hour
var WiggleRoom = 1; // Room in *PIPs to add/subtract from entries
int limit = 3; // max number of trades
Risk = 200; // Max Risk per trade
// DATE & TIME VARIABLES (TIMES ARE IN CHICAGO TIME (Central))
StartDate = 20100102; // Start date
EndDate = 20100105; // End date
AssetZone = CST; // Set timezone to Central (i.e. Chicago)
int marketstarthour = 8;
int marketstartminute = 30;
int marketendhour = 15;
int marketendminute = 0;
int StartTradingHour = 9;
int StartTradingMinute = 0;
int StopTradingHour = 14;
int StopTradingMinute = 30;
int OpenRangeHourEnds = 9; // Open Range Hour ends
int OpenRangeMinuteEnds = 0; // Open Range Minute ends
// COSTS
Spread = Commission = Slippage = RollLong = RollShort = 0; // Ignore costs
// INITRUN
if (is(INITRUN)) {
EntryHI = 0; EntryLO = 0; Range = 0; TradesToday = 0; TradesLong = 0;
TradesShort = 0; } // Clear Variables prior to initial run
while(asset(loop("SPX500"))) { // Define Assets
vars hi = series(priceHigh()); // Create Series of Highs
vars lo = series(priceLow()); // Create Series of Lows
// Print details for debugging
printf("\nA. %s - hi %.5f, lo %.5f\n",Asset,hi[0],lo[0]);
vars BarHI = series(MaxVal(hi,BarPeriod)); // Series of Max Highs
vars BarLO = series(MinVal(lo,BarPeriod)); // Series of Min Lows
vars BarRange = series(BarHI[0]-BarLO[0]); // Series of Hi-Lo Ranges
// Print details for debugging
printf("\nB. %s - BarHI %.5f, BarLO %.5f, BarRange %.5f\n",Asset,BarHI[0],BarLO[0],BarRange[0]);
if(lhour() == OpenRangeHourEnds && minute() == OpenRangeMinuteEnds) {
EntryHI = BarHI[0]+WiggleRoom*PIP;
EntryLO = BarLO[0]-WiggleRoom*PIP;
Range = BarRange[0]+(2*WiggleRoom*PIP);
// Print details for debugging
printf("\nC. %s - EntryHI: %.5f, EntryLO: %.5f, Range: %.5f\n",Asset,EntryHI,EntryLO,Range);
}
if (lhour() >= StartTradingHour && minute() >= StartTradingMinute && lhour() <= StopTradingHour && minute() <= StopTradingMinute ) {
tmf(); // Call TMF for trades
//enterLong(tmf);
//enterShort(tmf);
}
}
}
|
|
|
Re: TradeIsEntry appears to always be False
[Re: Zheka]
#472062
04/03/18 17:43
04/03/18 17:43
|
Joined: Sep 2017
Posts: 12
Trading4pips
OP
Newbie
|
OP
Newbie
Joined: Sep 2017
Posts: 12
|
ty @Zheka for the comments,
I had tried calling tmf with entry statements but commented them out because they did not work: //enterLong(tmf); //enterShort(tmf);
The main issue I'm having is that the manual and all of the examples I've found call the tmf using just enterLong(tmf) or enterShort(tmf). However, I want to enter into either 3 long or short trades (depending on which way the price breaks out) with specific stops and different targets. This is why I have set up these:
enterLong(0,EntryHI,Range,Range); // (Lots, Entry, Stop, Target) enterLong(0,EntryHI,Range,Range*2); enterLong(0,EntryHI,Range,Range*3); enterShort(0,EntryLO,Range,Range); enterShort(0,EntryLO,Range,Range*2); enterShort(0,EntryLO,Range,Range*3);
Obviously I'm doing something wrong, but reading the manual does not help as I can not find examples of what I'm trying to do. Any assistance would be greatly appreciated.
|
|
|
|