Dear TJ,
Many thanks. I have gone through a lot of material but still seem to be puzzled by a few concepts and how the script has to be written. To mention one as an example I have been trying to sort out one just now after spending more than 5 hours trying to test a piece of script and modifying it to get what it was intended to do I finally gave up. On this one I tried a simple rule where when the moving averages cross over to buy and sell after five days. However for purpose of optimisation, I would like to keep the barssinceentry on the input line. However I have problem referring to this value in the script so that it reads the value from the input line.
Code: Select all
inputs: Price( open ), FastLength( 50 ), SlowLength( 200 ), barssinceentry(4);
variables: var0( 0 ), var1( 0 ) ;
var0 = XAverage( Price, FastLength );
var1 = XAverage( Price, SlowLength ) ;
if var0 crosses over var1 then Buy ( "XIKON XMA2CrossLE" ) next bar at market;
if MarketPosition = 1 AND BarsSinceEntry = (to read from input line) then Sell next bar at Market;
.
There are also a few more which I am struggling with. Would any assistance be available?
Many thanks in advance.
Best regards,
XIKON
Before I get into your code, one word of advice:
Avoid using generic variable names like var0, value1, condition1, etc.,
I know the canned indicators have them, that's because they are re-gen'd from another source. For your own code, you should always create meaningful variable names, so that when you read the code, you can follow the logic easily. And when you re-visit your code in a few month's time, you do not have to scratch your head and spend hours trying to figure out the logic. This is important especially when you have expanded your logic and your "simple" code turned into hundreds of lines. This is critical if your code have to deal with your MONEY$$$. You do not want a small misunderstanding in variables turn into thousands of dollar in losses.
eg. which reads better?
Code: Select all
if var0 crosses over var1 then Buy...
if Fast.MA crosses over Slow.MA then Buy...
Just my 2 cents worth.