# Simple Standard Deviation Entries

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
pivot
Posts: 29
Joined: 07 Dec 2009
Been thanked: 2 times

### Simple Standard Deviation Entries

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;`

JoshM
Posts: 2090
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1526 times
Been thanked: 1487 times
Contact:

### Re: Simple Standard Deviation Entries

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;`

pivot
Posts: 29
Joined: 07 Dec 2009
Been thanked: 2 times

### Re: Simple Standard Deviation Entries

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.

TJ
Posts: 6636
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1919 times

### Re: Simple Standard Deviation Entries

pivot wrote: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;`

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

pivot
Posts: 29
Joined: 07 Dec 2009
Been thanked: 2 times

### Re: Simple Standard Deviation Entries

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

TJ
Posts: 6636
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1919 times

### Re: Simple Standard Deviation Entries

pivot wrote: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

viewtopic.php?f=16&t=6929