Using Code outside SetForeign function, inside the SetForeign Function

Is there anyway to make reference to code used outside the SetForeign function inside the SetForeign function? I realize that is incredibly vague, so I will try to clarify what I mean with an example.

Assume I have a short code which utilizes the SetForeign function that I want to apply to every single system of buy and sell rules that I use. For demonstration purposes, assume I just want this code to do something simple, like tell me what the current system would buy the stock "BHP.au" for. So no matter what symbol the current system is being explored/scanned over, I just want an output telling me what price BHP.au would have been bought for. I'll call this ForeignCode.afl.

SetForeign("BHP.au", True, True );

//	I do not wish to write buy/sell rules in here, as I want this code to be universal, so I can use #include_once to use it with any buy/sell rules
_TRACE( NumToStr( LastValue( BuyPrice ), 8.3 ) );

RestorePriceArrays( True );

I guess it would look something like this. Now with any system I run, I include it to give me my output of what the BuyPrice for BHP.au would have been. So say I have a super simple system of:

Calculation_Price = ( O + C ) / 2;
BuyPrice = Calculation_Price;

#include_once "Formulas\Custom\ForeignCode.afl"

Since I have set tradeprices=True, the BuyPrice array does indeed match the foreign security, but I believe that since the hard coding of the BuyPrice is outside The SetForeign - RestorePriceArrays part, the BuyPrice is that given by the settings in Analysis window, not the hard coding in afl.

I could correct this by just transferring these 2 lines:

Calculation_Price = ( O + C ) / 2;
BuyPrice = Calculation_Price;

inside the SetForeign - RestorePriceArrays part, but by doing that I have inserted system rules (buy/sell) into the code that I want to be universal and I can no longer apply it to any system.

Does anyone have a suggestion that would solve this problem? What I would be looking to do would be to keep the ForeignCode.afl code universal (without specific system rules) but to somehow access the rules of the system to calculate the values for the specific security.

I really do apologize if this post is unclear. If there's a specific question you have that would make this clearer, please don't hesitate to ask.

To try and simplify what I'm trying to say, I want the rules from outside the SetForeign() part, but if I type them directly into the SetForeign() part, I am essentially getting the arrays that have been calculated on a the base symbol. I'm looking for a way of getting the rules themselves that I can then apply to the Foreign symbol, not the arrays that will have been calculated on the base symbol.

Later edit - in typing this clarification up, I realized that this is literally what the function command is for. I apologize for the supreme stupidity of missing that. I will leave the post up I guess, in case anyone else has the same brain fart and does a search for it.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.