NexusFi: Find Your Edge


Home Menu

 





Powerlanguage - using functions to construct signals


Discussion in MultiCharts

Updated
    1. trending_up 2,588 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Powerlanguage - using functions to construct signals

  #1 (permalink)
Nabla76
Roma Italia
 
Posts: 17 since Jun 2019
Thanks Given: 11
Thanks Received: 5

I tried to transform a signal into a generic function and reuse it into a signal. It seemed to work, but, after some updates in OS, I am not able to make it work anymore (the same signal and the others, meanwhile, I wrote). Maybe some name conflict (variable names?) came up. Is it generally possible to make this transformation? Which rules must be followed? Thank you in advance for any suggestions.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
Trend Direction Force Index (TDFI)
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #2 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


Nabla76 View Post
I tried to transform a signal into a generic function and reuse it into a signal. It seemed to work, but, after some updates in OS, I am not able to make it work anymore (the same signal and the others, meanwhile, I wrote). Maybe some name conflict (variable names?) came up. Is it generally possible to make this transformation? Which rules must be followed? Thank you in advance for any suggestions.

I have just started using PowerLanguage, but I have a lot of EasyLanguage experience, which is very similar. First, a basic question: Did you try to recompile your function(s)? Maybe they need to be recompiled.

Here is my approach to turning an indicator into a function:
  1. Get the indicator code
  2. Create a new function: do not use any special character except underscore "_". I use a prefix before every function, example HSC_ is my prefix, so a function might be called HSC_NoLag_MA. This helps avoid naming conflicts
  3. Remove Alert criteria from the code
  4. Remove Plot criteria
  5. If the function generates more than one value, then create the 'numericref' or 'stringref' inputs to store the values to be used (see example below)
  6. Add a return statement (see example below)
  7. Compile and correct any errors
  8. Test the function in an indicator or signal

Here is an indicator that I turned into a function. I used a Return Type of TrueFalse (boolean), because my function generates three values that I need:

 
Code
// Alligator Indicator
[LegacyColorValue = TRUE];

Plot1(XAverage(MedianPrice,21)[8],"Plot1");  // Jaw
Plot2(XAverage(MedianPrice,13)[5],"Plot2");  // Teeth
Plot3(XAverage(MedianPrice,8)[3],"Plot3");    // Lips

Here is the function:

 
Code
//    HSC_Alligator Function
//    Based on Alligator indicator

Inputs:
	o_Jaw(NumericRef),
	o_Teeth(NumericRef),
	o_Lips(NumericRef) ;

o_Jaw = XAverage(MedianPrice,21)[8]   ;  
o_Teeth = XAverage(MedianPrice,13)[5] ;
o_Lips = XAverage(MedianPrice,8)[3]   ;

HSC_Alligator = True ;   // the return value

Here is how I would call the function:

 
Code
vars:
   o_Jaw(0),
   o_Teeth(0),
   o_Lips(0) ;

Value1 = HSC_Alligator(o_Jaw, o_Teeth, o_Lips) ; 

condition1 = o_Jaw > o_Teeth and o_Teeth > o_Lips ;

You can use the same approach with converting a Signal.

I hope this helps!

~vmodus

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
Nabla76
Roma Italia
 
Posts: 17 since Jun 2019
Thanks Given: 11
Thanks Received: 5



vmodus View Post
I have just started using PowerLanguage, but I have a lot of EasyLanguage experience, which is very similar. First, a basic question: Did you try to recompile your function(s)? Maybe they need to be recompiled.

Here is my approach to turning an indicator into a function:
  1. Get the indicator code
  2. Create a new function: do not use any special character except underscore "_". I use a prefix before every function, example HSC_ is my prefix, so a function might be called HSC_NoLag_MA. This helps avoid naming conflicts
  3. Remove Alert criteria from the code
  4. Remove Plot criteria
  5. If the function generates more than one value, then create the 'numericref' or 'stringref' inputs to store the values to be used (see example below)
  6. Add a return statement (see example below)
  7. Compile and correct any errors
  8. Test the function in an indicator or signal

Here is an indicator that I turned into a function. I used a Return Type of TrueFalse (boolean), because my function generates three values that I need:

 
Code
// Alligator Indicator
[LegacyColorValue = TRUE];

Plot1(XAverage(MedianPrice,21)[8],"Plot1");  // Jaw
Plot2(XAverage(MedianPrice,13)[5],"Plot2");  // Teeth
Plot3(XAverage(MedianPrice,8)[3],"Plot3");    // Lips

Here is the function:

 
Code
//    HSC_Alligator Function
//    Based on Alligator indicator

Inputs:
	o_Jaw(NumericRef),
	o_Teeth(NumericRef),
	o_Lips(NumericRef) ;

o_Jaw = XAverage(MedianPrice,21)[8]   ;  
o_Teeth = XAverage(MedianPrice,13)[5] ;
o_Lips = XAverage(MedianPrice,8)[3]   ;

HSC_Alligator = True ;   // the return value

Here is how I would call the function:

 
Code
vars:
   o_Jaw(0),
   o_Teeth(0),
   o_Lips(0) ;

Value1 = HSC_Alligator(o_Jaw, o_Teeth, o_Lips) ; 

condition1 = o_Jaw > and o_Teeth and o_Teeth > o_Lips ;

You can use the same approach with converting a Signal.

I hope this helps!

~vmodus

Thank you so much! Your sample is very detailed, I will definitely try your approach. I will surely let you know how it works! Thanks again!

Reply With Quote
Thanked by:
  #4 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


Nabla76 View Post
Thank you so much! Your sample is very detailed, I will definitely try your approach. I will surely let you know how it works! Thanks again!

You're welcome. I realize I made a mistake with the condition1 in the example, but you probably would have figured that out. Here is the correction:

 
Code
condition1 = o_Jaw > o_Teeth and o_Teeth > o_Lips ;
~vmodus

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on June 12, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts