NexusFi: Find Your Edge


Home Menu

 





TradeStation Pivot function conversion


Discussion in ThinkOrSwim

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




 
Search this Thread

TradeStation Pivot function conversion

  #1 (permalink)
petelegus72
raleigh, north carolina
 
Posts: 1 since Dec 2014
Thanks Given: 0
Thanks Received: 0

Hi Guys,

new here and to tos.

I'm trying to figure out the most efficient way to convert the TradeStation Pivot function for use in a tos study. I've looked and can't find similar code in tos. I really just want to be able to set the condition on a bar if it's a pivot or not. Any help would be appreciated... Here is the TS function:

{ Multiple-output function; see MULTIPLE-OUTPUT FUNCTIONS note below }

inputs:
Price( numericseries ),
Length( numericsimple ),
LeftStrength( numericsimple ),
RightStrength( numericsimple ),
Instance( numericsimple ),
HiLo( numericsimple ), { pass in 1 for PivotHigh(Bar), -1 for PivotLow(Bar) }
oPivotPrice( numericref ),
oPivotBar( numericref ) ;

variables:
CandidatePrice( 0 ),
LengthCntr( 0 ),
StrengthCntr( 0 ),
InstanceCntr( 0 ),
PivotTest( false ),
InstanceTest( false ) ;

InstanceCntr = 0 ;
InstanceTest = false ;
LengthCntr = RightStrength ;
while LengthCntr < Length and InstanceTest = false
begin
{ GET NEXT MOST RECENT CandidatePrice & SET STARTING ASSUMPTION
THAT IT IS A Pivot: }
CandidatePrice = Price[LengthCntr] ;
PivotTest = true ;
{ COMPARE CandidatePrice TO LeftStrength BARS ON LEFT: }
StrengthCntr = LengthCntr + 1 ;
while PivotTest = true and StrengthCntr - LengthCntr <= LeftStrength
begin
if ( HiLo = 1 and CandidatePrice < Price[StrengthCntr] )
or ( HiLo = -1 and CandidatePrice > Price[StrengthCntr] ) then
PivotTest = false
else
StrengthCntr = StrengthCntr + 1 ;
end ;
{ IF CandidatePrice SURVIVED LEFT COMPARISON, NOW COMPARE TO
RightStrength BARS ON RIGHT: }
StrengthCntr = LengthCntr - 1 ;
while PivotTest = true and LengthCntr - StrengthCntr <= RightStrength
begin
if ( HiLo = 1 and CandidatePrice <= Price[StrengthCntr] )
or ( HiLo = -1 and CandidatePrice >= Price[StrengthCntr] ) then
PivotTest = false
else
StrengthCntr = StrengthCntr - 1 ;
end ;
{ IF CandidatePrice SURVIVED OVERALL AS Pivot, INCREMENT InstanceCntr: }
if PivotTest = true then
InstanceCntr = InstanceCntr + 1 ;
{ IF InstanceCntr HAS REACHED REQUIRED COUNT, THEN THIS IS THE DESIRED Pivot,
ELSE INCREMENT LengthCntr TO PREPARE TO GET AND TEST NEXT CANDIDATE PRICE: }
if InstanceCntr = Instance then
InstanceTest = true
else
LengthCntr = LengthCntr + 1 ;
end ;
if InstanceTest = true then
begin
oPivotPrice = CandidatePrice ;
oPivotBar = LengthCntr + ExecOffset ;
Pivot = 1 ; { return 1 if required pivot found }
end
else
begin
oPivotPrice = -1 ;
oPivotBar = -1 ;
Pivot = -1 ; { return -1 if required pivot not found }
end ;

{
MULTIPLE-OUTPUT FUNCTIONS

A multiple-output function has two types of parameters or "inputs" - input parameters
and input/output parameters. The values of the input parameters are passed into the
multiple-output function, but not modified by the function. The values of the input/
output parameters are passed into the multiple-output function, modified by it, and
the modified values are then inherited by - or output to - the calling routine.

The input/output parameters are often used for output purposes only, i.e., the
incoming values are ignored. The outputs are in addition to the function return. In
multiple-output functions, the function return is generally used to return an error
code, though sometimes the return may simply be a dummy value.

The input/output parameters are declared with a "ref" suffix (such as "numericref") in
the multiple-output function's declaration statements. For further clarity, the names
of the input/output parameters are generally prefixed with an "o" in the function as
well as in all the routines that call the function.

The built-in single-return WRAPPER FUNCTIONS that call the multiple-output functions
are specialized calling routines designed to offer simplified, alternate pathways to
the functionality of the underlying multiple-output functions. In the wrapper
functions, the input/output parameters are declared as local variables and generally
initialized to zero. They are passed through to the multiple-output function without
further modification. After the call, the wrapper function picks out the single
output of interest and assigns it as the return of the wrapper function.
}

{ ** Copyright (c) 2001 - 2010 TradeStation Technologies, Inc. All rights reserved. **
** TradeStation reserves the right to modify or overwrite this analysis technique
with each release. ** }


Thanks,
Pete

Reply With Quote




Last Updated on December 19, 2014


© 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