unable to get atr of data2  [SOLVED]

Questions about MultiCharts and user contributed studies.
ravel44
Posts: 28
Joined: 05 Jul 2012
Has thanked: 7 times

unable to get atr of data2

Postby ravel44 » 27 Oct 2015

Hello !
I have a 1 min chart of FB as data1 and a daily chart of FB as data2.
Something is wrong with this code since it is not returning the ATR of data2 :I m being stopped a few cents below my buy while the ATR is 2,2. Not sure what s wrong. Thanks for the help in advance !

Code: Select all

var:
atr(0,data2);
atr=average(truerange, 14) of data2; // value ATR


if C>C[4] then buy 100 shares next bar at market;
setstoploss(atr);
Attachments
Screen Shot 2015-10-27 at 5.47.37 PM.png
(41.17 KiB) Downloaded 730 times

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: unable to get atr of data2

Postby TJ » 27 Oct 2015

Hello !
I have a 1 min chart of FB as data1 and a daily chart of FB as data2.
Something is wrong with this code since it is not returning the ATR of data2 :I m being stopped a few cents below my buy while the ATR is 2,2. Not sure what s wrong. Thanks for the help in advance !

Code: Select all

var:
atr(0,data2);
atr=average(truerange, 14) of data2; // value ATR


if C>C[4] then buy 100 shares next bar at market;
setstoploss(atr);
Hello,
::
I have another question and is what does Portfolio_CurrentEntries measures?
::
Before you go any further,
please get yourself acquainted with the Wiki.


Go to the "Support" tab at the top of this page,
click on the Wiki,
go to #8 PowerLanguage Keyword Reference

look under [+] Strategy Orders‎ (28)
You have everything you need there.

Study the definition and usage examples of the keyword:

SetStopLoss

ravel44
Posts: 28
Joined: 05 Jul 2012
Has thanked: 7 times

Re: unable to get atr of data2

Postby ravel44 » 27 Oct 2015

Hello !
I have a 1 min chart of FB as data1 and a daily chart of FB as data2.
Something is wrong with this code since it is not returning the ATR of data2 :I m being stopped a few cents below my buy while the ATR is 2,2. Not sure what s wrong. Thanks for the help in advance !

Code: Select all

var:
atr(0,data2);
atr=average(truerange, 14) of data2; // value ATR


if C>C[4] then buy 100 shares next bar at market;
setstoploss(atr);
Hello,
::
I have another question and is what does Portfolio_CurrentEntries measures?
::
Before you go any further,
please get yourself acquainted with the Wiki.


Go to the "Support" tab at the top of this page,
click on the Wiki,
go to #8 PowerLanguage Keyword Reference

look under [+] Strategy Orders‎ (28)
You have everything you need there.

Study the definition and usage examples of the keyword:

SetStopLoss

Thank U but I still do not get it. The code compile correctly and the output gives a correct answer for the ATR. I don t get why the stop ends up a few cents away from my buys instead of the value of the ATR.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: unable to get atr of data2

Postby TJ » 27 Oct 2015

::
Study the definition and usage examples of the keyword:

SetStopLoss

Thank U but I still do not get it. The code compile correctly and the output gives a correct answer for the ATR. I don t get why the stop ends up a few cents away from my buys instead of the value of the ATR.
Study again the definition and usage examples of SetStopLoss.

What should be inside the bracket?

ravel44
Posts: 28
Joined: 05 Jul 2012
Has thanked: 7 times

Re: unable to get atr of data2

Postby ravel44 » 27 Oct 2015

::
Study the definition and usage examples of the keyword:

SetStopLoss

Thank U but I still do not get it. The code compile correctly and the output gives a correct answer for the ATR. I don t get why the stop ends up a few cents away from my buys instead of the value of the ATR.
Study again the definition and usage examples of SetStopLoss.

What should be inside the bracket?
I do know that the basic definition shows numbers ( ex: setstoploss(60) ) however I found many codes with variables instead of numbers.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: unable to get atr of data2  [SOLVED]

Postby TJ » 27 Oct 2015

I do know that the basic definition shows numbers ( ex: setstoploss(60) ) however I found many codes with variables instead of numbers.

SetStopLoss
Closes out the entire position or the entry if the loss reaches the specified currency value;
eg.

$500
$1000


Without the "$" of course

The value can be a variable; what is the dollar amount you want?

ravel44
Posts: 28
Joined: 05 Jul 2012
Has thanked: 7 times

Re: unable to get atr of data2

Postby ravel44 » 27 Oct 2015

I do know that the basic definition shows numbers ( ex: setstoploss(60) ) however I found many codes with variables instead of numbers.

SetStopLoss
Closes out the entire position or the entry if the loss reaches the specified currency value;
eg.

$500
$1000


Without the "$" of course

The value can be a variable; what is the dollar amount you want?
Got it thank U. I coded a line so that the stop will be based on the ATR and give the max loss in $

Code: Select all

var:
var3(0),
atr(0,data2);
atr=average(truerange data2, 14); // value ATR

var3=(entryprice+atr)*100-entryprice*100;


if C>C[4] then buy 100 shares next bar at market;
setstoploss(var3);


Return to “MultiCharts”