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.
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/1311:49.
Re: New programer frustrations
[Re: DMB]
#428538 08/29/1312:3808/29/1312:38
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/1312:5808/29/1312:58
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/1313:4009/01/1313:40
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.
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.
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.
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.