Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, alibaba), 1,184 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
New programer frustrations #428520
08/29/13 09:05
08/29/13 09:05
Joined: Aug 2013
Posts: 124
D
DMB Offline OP
Member
DMB  Offline OP
Member
D

Joined: Aug 2013
Posts: 124
Hi all

I am banging my head against what must be some very simple coding problems...the basic fundamental type. A few moments of someones time would be greatly appreciated.

I am setting up a simple 'Open +/- Previous range' breakout algorithm with a "First Profitable Opening' exit (yeah...Larry Williams stuff. I have done this on previous software packages, but can't do it here. Below is the code and the chart. The code contains other non-relevant statements that I will eventually use. For now, just focus on the enterShort and exitShort parts.

The problems:

1. Getting Zorro to enter at the Open - 30% of yesterdays range. When I make the 'Entry = shortentry;' negative to indicate stop entry, I get fills in places where the price did not trade.

2. Getting Zorro to exit. I assume the problem is in the IF statement.

Thanks in advance.

EDIT: I removed the above mentioned non-relevant code and replaced the graph.

Quote:

function run()
{

set(PARAMETERS+FACTORS+LOGFILE);
LookBack = 100;
StartDate = 20130101;
EndDate = 20131230;

while(asset(loop("AUD/USD","EUR/USD","GBP/USD","NZD/USD","USD/CAD","USD/CHF","USD/JPY")))
{

BarPeriod = 1400;

var shortentry = priceOpen() - (0.3 * (priceHigh(1)-priceLow(1)));

TimeWait = 1; // Remove pending orders at end of market day

if ( TRUE )
{

Entry = shortentry;
enterShort();
}


if ( TradeResult > 0 )
{
exitShort();
}
}

PlotScale = -10;
PlotWidth = 1400;
PlotHeight1 = 500;

}


Attached Files
Untitled.png (8 downloads)
Last edited by DMB; 08/29/13 09:30.
Re: New programer frustrations [Re: DMB] #428531
08/29/13 10:42
08/29/13 10:42
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Your bar period is not a day, in case you wanted daily bars.

I'm not sure what entry condition you need, but your script sets an entry stop, not an entry limit. Aside from that, the entry looks ok.

The exit makes no sense to me. Is this supposed to be some sort of profit target? When do you want your trade to exit?

Re: New programer frustrations [Re: jcl] #428535
08/29/13 11:45
08/29/13 11:45
Joined: Aug 2013
Posts: 124
D
DMB Offline OP
Member
DMB  Offline OP
Member
D

Joined: Aug 2013
Posts: 124
Maybe I can figure out the entry on my own. The entry is a meant to be a stop entry. The range to break out of is set by the open.

The exit....had a bit of time to think about it. Clearly I am not thinking in source code yet. I want to enter one bar, then if the next bar's open is profitable, then exit. So I have tried the condition below, with a delay of one bar using the TradeTime variable and checking for profitability for TradeResult.

if ( TradeTime == 1 && TradeResult > 0 )

The alternative is to compare the priceOpen() < TradePriceOpen.

Does the potential for multiple trades complicate things?

And...yes...oops...1440.

Last edited by DMB; 08/29/13 11:49.
Re: New programer frustrations [Re: DMB] #428538
08/29/13 12:38
08/29/13 12:38
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Ok, for an entry stop your code is correct.

Programmers do not think in source code. They just think how to describe their task as clear as possible. Then the source code appears automatically. If you want to exit all trades that are in profit at the next bar's open, the exit code snippet would look like this:

Code:
for(open_trades)
  if(TradeIsOpen and TradeResult > 0)
    exitTrade(ThisTrade);



This would of course cause a margin call sooner or later when a trade does not reach the profit zone.

Re: New programer frustrations [Re: jcl] #428540
08/29/13 12:58
08/29/13 12:58
Joined: Aug 2013
Posts: 124
D
DMB Offline OP
Member
DMB  Offline OP
Member
D

Joined: Aug 2013
Posts: 124
Thanks...I will have a stop as well as filters. The code above is the first step.

As you can expect, an exit like this will increase the system's accuracy to the detriment of the reward/risk ratio. I might end up having a trailing stop exit instead. Just starting with Williams' original work and developing it from there.

Re: New programer frustrations [Re: DMB] #428681
09/01/13 13:40
09/01/13 13:40
Joined: Aug 2013
Posts: 124
D
DMB Offline OP
Member
DMB  Offline OP
Member
D

Joined: Aug 2013
Posts: 124
Programming error I don't understand. The two lines involved:

var BreakoutValue = 0.3 * (priceHigh(1)-priceLow(1));
...
plot("BreakoutValue",BreakoutValue,NEW,BLUE);

The error referring to the plot function:
'BreakoutValue' undeclared identifier

As far as I can tell I have declared it.

Last edited by DMB; 09/01/13 13:41.
Re: New programer frustrations [Re: DMB] #428682
09/01/13 14:27
09/01/13 14:27

A
acidburn
Unregistered
acidburn
Unregistered
A



Originally Posted By: DMB
Programming error I don't understand. The two lines involved:

var BreakoutValue = 0.3 * (priceHigh(1)-priceLow(1));
...
plot("BreakoutValue",BreakoutValue,NEW,BLUE);

The error referring to the plot function:
'BreakoutValue' undeclared identifier

As far as I can tell I have declared it.


Everything seems fine with your example.

Carefully check in which line you got error, you might have accidentaly referenced BreakoutValue somewhere in the code where it's not yet declared (that is above the declaration). Unfortunately, Zorro is buggy, you have to search for the error one or two lines above the line number that Zorro reports.

Undeclared identifier [Re: DMB] #428685
09/01/13 14:55
09/01/13 14:55
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
The error message just means the compiler finds no variable with the name 'BreakoutValue'. So your declaration must be at a wrong place, like in a different function or at a place AFTER the plot command. If you declare a variable inside a function, its unknown outside that function.

Re: Undeclared identifier [Re: Spirit] #428697
09/02/13 00:04
09/02/13 00:04
Joined: Aug 2013
Posts: 124
D
DMB Offline OP
Member
DMB  Offline OP
Member
D

Joined: Aug 2013
Posts: 124
The problem seems to be that the use of BreakoutValue is inside an asset while loop. When I took away the loop and just ran it on a single drop-down menu selected asset, I got my plot.

Therefore, I guess I have to get the code right for one asset and then apply the while loop for different assets when I no longer need the chart for debugging.

Re: Undeclared identifier [Re: DMB] #428710
09/02/13 08:43
09/02/13 08:43
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
My advice: Do not "solve" a problem by just taking away some code.

Find and fix the mistake. In case of a mere syntax error it's very easy because the compiler tells you what's wrong. You only need to find out why.

It's more difficult to find bugs that are no syntax errors. But if you already surrender to a syntax error, you have no chance to accomplish anything. Besides, you just need to post your code here and people will tell you what's wrong.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1