powerlanguage

Questions about MultiCharts and user contributed studies.
rbn60604@yahoo.com
Posts: 24
Joined: 13 Mar 2012
Has thanked: 11 times

powerlanguage

Postby rbn60604@yahoo.com » 08 May 2012

Can someone give an example of 2 different things I'm trying to code if possible...

1) I'm trying to compare the current close to EACH of the last say 60 closes...so I'm trying to make sure that the current close has been > than ALL past 60 closes....NONE of the closes of the last 60 days can be lower than the current.

2) I'm trying to also to compare the current close to the 30th ago close....i.e., does today's close cross over or under the 30th day ago close.


I'm pretty close to being able to write the code to both but haven't got there yet.

Thanks for your help.

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: powerlanguage

Postby bowlesj3 » 08 May 2012

I am pretty sure the following code will cover the first one.

Code: Select all

If barstatus=2 then {Execute this code on the last tick of the bar}
   Begin
   If close > Highest(close,59)[1] then {search back 59 closes starting from 1 before}
      condition1 = true {what you are looking for is true}
   else
      condition1 = false;  {what you are looking for is false}
   end;

You can find the highest function in the Editor and study it. All it does is execute a loop working backward. It is set up to call another function that can take in any value like, close, high, low, open, RSI, etc. I am doing this from memory so make sure you double check the results. What you could to is put the output of the Highest(close,59)[1] into value1 so you can print it before doing the test then you can scan the bars to see if it is correct.

The second one is tricky (I suspect). You would probably want to know if the prices have gone above and below the close[30] more than one time (it could be 5 times and just testing close[30] won't tell you this). You may need to set up a swing logic of some sort with a flag that is set to > or < or =. You would count the cross overs maybe. You would need to keep incrementing the [?] part with an increasing number. I think you may be on your own in this one to work through the logic. It would not be hard if you just want to go back one time and you loop back 30 bars (actually very easy - just loop backwards and start counting or whatever you want). You could go back 30 bars on each new bar looking for a pattern. That would not be too hard. You would execute this loop when you get the last tick as detected by barstatus=2. If your study is not executing on every tick they you do not need to test the barstatus=2.

If you are new to Easy Language, once you get the very basics down, start scanning the top descriptions of the commands 1 by 1 to get a feel for what is out there and create a list of ones that sound useful. Do this again after your last time you did it (maybe 3 or 4 months later). It is amazing how the 2nd and 3rd time you do this you get ideas for commands that just went over your head the 1st and 2nd time through. Each scan may take you 7 days at about 1 hour a night (a guess). However it is worth it. This overview (drill down) approach allows you to get where you want to go much faster. Go back and study the commands in detail when you need them.
These users thanked the author bowlesj3 for the post (total 4):
Stan Bokovfurytraderrbn60604@yahoo.comTIKITRADER

rbn60604@yahoo.com
Posts: 24
Joined: 13 Mar 2012
Has thanked: 11 times

Re: powerlanguage

Postby rbn60604@yahoo.com » 08 May 2012

Thanks very much for your detailed reply....I am new to power language but am reasonably confident I can figure something out from your answer.

Really appreciate the help.

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: powerlanguage

Postby bowlesj3 » 08 May 2012

Hi,

Make sure you include in your reading this thread. It contrains some rather strange things about the EL language that even programmers like myself had trouble with until we finally figure out what EL is doing.
viewtopic.php?f=16&t=7466
Having said that some of the links have been lost because of a server change. I just checked this link and it is correct. However the links within it may fail to find the correct page. If some do not find the page please place the link in here and I will see if I can find the ones that may be mine.

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: powerlanguage

Postby bowlesj3 » 09 May 2012

I want back the above link to check to make sure IntraBarPersist was in there. I thought it was but it appears not. So I did that up by putting this entry right at the very top post and this is a copy of what I placed there.

I think the most important thing to be sure you understand before you program anything is the intrabarpersist key word and how it related to the underlying MaxBarsBack tables in MC. As of 2012/May/09 the Wiki does not give you much on the intrabarpersist. Here is a link that gives you more info and some test scripts to help understand it.
viewtopic.php?f=5&t=6871&hilit=intrabarpersist

I plan on updating the Wiki hopefully soon and this will be the first one. Recalculate is another good command to understand but it is not supported. It should be in the Wiki because just understanding it alone helps.
These users thanked the author bowlesj3 for the post:
kiasom

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 300 times

Re: powerlanguage

Postby Stan Bokov » 09 May 2012

@rbn60604@yahoo.com - please make sure you click the Thanks button for those posts that you find helpful.
These users thanked the author Stan Bokov for the post (total 2):
TJkiasom

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: powerlanguage

Postby bowlesj3 » 12 May 2012

I have a few databases I can use to store links and I can string search the descriptor.

I have just been scanning for all my useful posts and putting those links in one of these database (it will save me a lot of time). I found this link.

MC/EL frequently triggered traps (how to avoid)
viewtopic.php?f=16&t=7665

I think this is the one that I was meaning to give out.
These users thanked the author bowlesj3 for the post:
TJ

rbn60604@yahoo.com
Posts: 24
Joined: 13 Mar 2012
Has thanked: 11 times

Re: powerlanguage

Postby rbn60604@yahoo.com » 15 May 2012

I had posted a question about powerlanguage and received a response but the example didn't seem to work so I figured I'd post the code to see what the problem is...

If barstatus = 2 then begin

if close > Highest(close,40)[1] then

alert (text("C H prev 40", highest(close,40)));
alert (text("40 d close", close[40]));

end;


What I thought this code would do is compare the current close to the previous 40 closes and then alert IF THE CLOSE WAS GREATER THAN ALL previous 40 closes.....it for sure doesnt do that....can anyone explain or give an example of how I can fix this?

Thank you

User avatar
TJ
Posts: 6609
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1912 times

Re: powerlanguage

Postby TJ » 15 May 2012

When you are posting codes,
highlight the text, then click on the "code" button on the top of the message window,
and your code will look like this:

Code: Select all

If barstatus = 2 then begin

if close > Highest(close,40)[1] then

alert (text("C H prev 40", highest(close,40)));
alert (text("40 d close", close[40]));

end;

User avatar
TJ
Posts: 6609
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1912 times

Re: powerlanguage

Postby TJ » 15 May 2012

rbn60604@yahoo.com wrote:I had posted a question about powerlanguage and received a response but the example didn't seem to work so I figured I'd post the code to see what the problem is...

If barstatus = 2 then begin

if close > Highest(close,40)[1] then

alert (text("C H prev 40", highest(close,40)));
alert (text("40 d close", close[40]));

end;


What I thought this code would do is compare the current close to the previous 40 closes and then alert IF THE CLOSE WAS GREATER THAN ALL previous 40 closes.....it for sure doesnt do that....can anyone explain or give an example of how I can fix this?

Thank you


re: it for sure doesnt do that

then can you tell us what did it do?

can you post a screen shot? (with notes?)

rbn60604@yahoo.com
Posts: 24
Joined: 13 Mar 2012
Has thanked: 11 times

Re: powerlanguage

Postby rbn60604@yahoo.com » 15 May 2012

The alert that is generated for ZWK2 (May Wheat, IB feed) looks like this...


5/15/2012 10:48:50 PM
Source: rbn2
Instrument: ZW MAY 12
Resolution: 1 Day
Price: 604.00
Message: 40 d close 672.00


The alert says 'Price: 604.00', which should show the Highest Close of the past 40 days, from 1 bar prior (what I think the code asks for) shows only Today's Close (604.00) regardless of past closes. The contract has been making new LOWS since the end of March, it shouldn't alert anything unless the Close is > than all of previous 40 days (I'm obviously wrong since it doesn't work).

Did I use the highest function incorrectly?....its not just this contract FYI, I added the signal to a market scanner window, and it alerts for a bunch of contracts but approximately 50% are wrong like the ZWK2 example.

Sorry to be a pain, but its a little difficult when the documentation seems to say that it (highest function) should check each Close of the previous 40 Closes, compared to the current Close. I'm just getting started and am trying to write what I think should be fairly simple commands/code and completely appreciate the help.

Any help would be great.

Thank you

User avatar
TJ
Posts: 6609
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1912 times

Re: powerlanguage

Postby TJ » 15 May 2012

rbn60604@yahoo.com wrote:The alert that is generated for ZWK2 (May Wheat, IB feed) looks like this...


5/15/2012 10:48:50 PM
Source: rbn2
Instrument: ZW MAY 12
Resolution: 1 Day
Price: 604.00
Message: 40 d close 672.00


The alert says 'Price: 604.00', which should show the Highest Close of the past 40 days, from 1 bar prior (what I think the code asks for) shows only Today's Close (604.00) regardless of past closes. The contract has been making new LOWS since the end of March, it shouldn't alert anything unless the Close is > than all of previous 40 days (I'm obviously wrong since it doesn't work).

Did I use the highest function incorrectly?....its not just this contract FYI, I added the signal to a market scanner window, and it alerts for a bunch of contracts but approximately 50% are wrong like the ZWK2 example.

Sorry to be a pain, but its a little difficult when the documentation seems to say that it (highest function) should check each Close of the previous 40 Closes, compared to the current Close. I'm just getting started and am trying to write what I think should be fairly simple commands/code and completely appreciate the help.

Any help would be great.

Thank you


POST A SCREEN SHOT

draw a line on the screen shot that shows the highest high of whatever

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: powerlanguage

Postby bowlesj3 » 16 May 2012

I think the problem is your if statement. If you want both alerts when the if statement is true you need to put them in the begin and end keywords as below. I used a print statement because the alert only occurs on the last bar on the chart "lastbaronchart". In your statement you are missing the begin and end statements to only the first alert would execute. However if it executes before the last bar I do not think you will see it.

Also I show the close from 41 bars back because that should be the first close (make that the last close) that is tested by the highest statement.

Lastly, I put a spacer print statement in. You might want to use the Time statement in the print so you can see where this occurred.

Code: Select all

If barstatus = 2 then
   begin
   if close > Highest(close,40)[1] then
          begin
          Print( File("C:\A_TestHighest.txt"),
            "highest(close,40)[1]=" ,
            highest(close,40)[1],
            " ");
          Print( File("C:\A_TestHighest.txt"),
            "close=" ,
            close,
            " ");
          Print( File("C:\A_TestHighest.txt"),
            "close[41]=" ,
            close[41],
            " ");
          Print( File("C:\A_TestHighest.txt"),
            " ");
          end;
   end;
   



Try this. Also try creating a variation to replace 40 with a barsback input to test a small number to confirm in your mind that the highest is working. These types of small tests are the way of the life of a programmer (step by step confirmation of your code to find the answers as you go).

Code: Select all

Inputs: BarsBack(5);

If LastBarOnChart then
    begin
    if close > Highest(close,40)[1] then
        begin
        alert (text("C H prev 40", highest(close,40)));
        alert (text("40 d close", close[40]));
        End;
    end;
These users thanked the author bowlesj3 for the post:
rbn60604@yahoo.com

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: powerlanguage

Postby bowlesj3 » 16 May 2012

I was going to leave this out but I have changed my mind for reasons I will not divulge.

When I was learning unix shell scripting (we are talking a full time professional who decided to learn a new programming language) I would read the manual for an hour in the morning (over coffee of course) and list tests of the commands I wanted to do test. Then at night after work I would sit down for 3 hours and make these tests on the computer. I did this for 1.5 years (if I remember correctly) every night without fail (7 days a week). I probably had 10 to 15 tests a night.

Now this is how you learn a language really really well. So since I think the problem is in the if statement rather than that highest function the best bet is to go back and read that section of the manual and do some tests just as I did. As your read each sentence of the manual regarding the if statement prepare a test (dissect every sentence if you have to). If need be do the same with the print statement and the alert. TEST everything you listed. Once you are done for sure you will understand it much better.

I have to say that I have not done this for EL but if I have a problem I will disect it with the print statement. Also use the fileappend statement since if your code bombs (aborts with the orange box) you still have the output where as with the print statement you loose it (a useful trick for your tests). Use the delete statement to delete the fileappend output.
These users thanked the author bowlesj3 for the post:
rbn60604@yahoo.com

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: powerlanguage

Postby bowlesj3 » 17 May 2012

After seeing the problem code above and thinking about the posts in this thread, I realized that the FAQs section needs a new thread titled "EL debugging (trouble shooting) guide". It makes sense because this may actually be the biggest FAQ area. TJ agrees. It will be started late this weekend most likely. It will have general bug resolution procedures, bug reduction procedures and tips. The idea is that help may not always be available and if the procedures in this thread are followed then all users will be able to solve most of their simple programming problems fairly quickly. More experienced programmers/users will be able to point new users (especially those who have no programming experience at all) to this thread (avoiding duplicated work) and saving them a lot of time.
These users thanked the author bowlesj3 for the post:
rbn60604@yahoo.com

rbn60604@yahoo.com
Posts: 24
Joined: 13 Mar 2012
Has thanked: 11 times

Re: powerlanguage

Postby rbn60604@yahoo.com » 17 May 2012

Thanks to both of you, very good idea to have the EL debugging FAQ, think it would be great to be able to go to that for references and just helps to learn to 'think' like a programmer a little more....seems like if you know how to debug, you know programming in a sense.


Thanks again bowlesj3 and TJ.


I'm sure I'll still need to bug you again, but nice that you took the time.

bowlesj3
Posts: 2028
Joined: 21 Jul 2007
Has thanked: 174 times
Been thanked: 405 times

Re: powerlanguage

Postby bowlesj3 » 17 May 2012

I started the thread tonight because I wanted to get examples of the fileappend command out there. If you have a script that is bombing on you the only way you can debug it is with FileAppend since it does not get deleted when the script aborts.

Have fun.
viewtopic.php?f=16&t=10397


Return to “MultiCharts”