Page 1 of 1

Simple Standard Deviation Entries

Posted: 26 Jul 2011
by pivot
I am trying to write some code for simple Standard Deviation Entries. This would be on current bar +/- X SD there would be Long limit order and a short limit order on the current bar


Here is the code I have written code someone with more coding skills then me take a look and help me to correct this as I am not sure what I am missing.

Code: Select all

Inputs:
SDLen (100),
NSD ( 2 );

Variables:
vSDEnt(0);

vSDEnt = StandardDev( c, SDLen, 2 );

{ Variables for entry and exit prices }
Value1 = vSDEnt * NSD;

variables:
vMP (0),
EntPrL (0),
EntPrS (0);

vMP = marketposition;
EntPrL = c[1] - value1;
EntPrS = c[1] + value1;

if currentbar >2 and vMP = 0 then
begin
Buy currentbar at EntPrL Limit;
and
Sellshort Currentbar at EntPrS limit;
end;
Thanks in Advance

Re: Simple Standard Deviation Entries

Posted: 26 Jul 2011
by JoshM
Hi Pivot,

Looks good, though there is one logical error in it (in my opinion). You enter a position with a EntPrL limit or EntPrS limit price, that you want to have submitted at the current bar. However, these limit prices are calculated using the vSDEnt variable, which holds the StdDev value for the *current* bar. Since the (true) closing value is only known at the end of the bar, submitting a limit order using that value during a bar might introduce a error in your strategy.

Perhaps something like this might work:

Code: Select all

Inputs: SDLen (100),
NSD ( 2 );

Variables: vSDEnt(0),
vMP(0),
EntPrL(0),
EntPrS(0);

vSDEnt = StandardDev( c, SDLen, 2 );
Value1 = vSDEnt * NSD;
vMP = marketposition;

EntPrL = c[1] - value1;
EntPrS = c[1] + value1;

if vMP = 0 then begin
Buy next bar at EntPrL limit;
Sellshort next bar at EntPrS limit;
end;

Re: Simple Standard Deviation Entries

Posted: 26 Jul 2011
by pivot
Thanks JoshM -

I want to enter the current bar so would the logic be corrected if in the SD calculation I change it to c[1] reference the previous bars close to calculate SD. Something like this

Code: Select all

vSDEnt = StandardDev( c[1], SDLen, 2 );



but I still can't get it to compile and there are still errors.

I want to have orders placed on current bar and not the next bar. Next bar really changes my logic.

Thanks in advance for your help.

Re: Simple Standard Deviation Entries

Posted: 26 Jul 2011
by TJ
I am trying to write some code for simple Standard Deviation Entries. This would be on current bar +/- X SD there would be Long limit order and a short limit order on the current bar


Here is the code I have written code someone with more coding skills then me take a look and help me to correct this as I am not sure what I am missing.

Code: Select all

Inputs:
SDLen (100),
NSD ( 2 );

Variables:
vSDEnt(0);

vSDEnt = StandardDev( c, SDLen, 2 );

{ Variables for entry and exit prices }
Value1 = vSDEnt * NSD;

variables:
vMP (0),
EntPrL (0),
EntPrS (0);

vMP = marketposition;
EntPrL = c[1] - value1;
EntPrS = c[1] + value1;

if currentbar >2 and vMP = 0 then
begin
Buy currentbar at EntPrL Limit;
and
Sellshort Currentbar at EntPrS limit;
end;
Thanks in Advance
1. you cannot buy at current bar, only at next bar.

2. look up IntraBarOrderGeneration

3. You have an extraneous "and" in between the buy and sell orders.

4. wrong application of the keyword "currentbar". Please look up the keyword dictionary for definition and usage example.

5. Go through the examples in these ebooks would help:
Getting Started with EasyLanguage
The essential EasyLanguage programming guide

Re: Simple Standard Deviation Entries

Posted: 26 Jul 2011
by pivot
Thanks TJ

is it possible to refer calculations on Data2 and then executing on data series 1?

This could be a work around for my logic.

regards

p

Re: Simple Standard Deviation Entries

Posted: 26 Jul 2011
by TJ
Thanks TJ

is it possible to refer calculations on Data2 and then executing on data series 1?

This could be a work around for my logic.

regards

p

Please read point #5 in post #4 above


Please also read post #4 here:
viewtopic.php?f=16&t=6929

Re: Simple Standard Deviation Entries

Posted: 29 Jul 2011
by furytrader
I think your best bet is to try intrabarordergeneration