Trade Algorithm. Complete description.

 A custom trading type is when the user completely controls traffic distribution. You will have to define criteria to be used when distinguishing traders who'll get most traffic from your site. You must have some basic PHP knowledge as well as understanding of trading concepts. Beginners, be very careful!

All right, let's start.

  • Basic notions

  • Step 1: P1, P2, P3 Calculation

  • Step 2: Creation of Points1, Points2, Points3

  • Control

Basic notions
Please go to Settings->Out settings -> '. After that, there will be five main channels in your trade :

  1. Hourly forces

  2. Fast forces (forces 'right now').

  3. Calculated points P1 (main).

  4. Calculated points P2.

  5. Calculated points P3.

In the menu you can set the percentage of traffic that will go to each flow:


Here, 25% of total traded traffic will go to hourly forces, 25% - to 'timed forces', 30% - to P1, 10% to P3 and 10% - to P3.

This is how out.php works:

  1. With a defined probability the script is looking for the trader to give away hourly forces. If such a trader is not found (hourly forces are already given away or are not set), we proceed to point 2:

  2. With a defined probability the script is looking for the trader to give away fast forces. If such a trader is not found (fast forces are already given away or are not set), we proceed to point 3:

  3. With a defined probability the script is looking for a trader in P2. If such a trader is not found, we proceed to point 4: 4. With a defined probability the script is looking for a trader in

  4. If such a trader is not found, we proceed to point 5:

  5. The script is looking for a trader in P1.

Data collection for out.php is done in 2 steps.

First step: a value must be calculated for each trader (points) - $P1 (necessary), $P2 and/or $P3, using given variables (specific trade characteristics).
You won't have to calculate points for forces - this is done automatically.

All the traders are then sorted by points.

Second step: using this traders list, you'll have to pick the best ones - $N1 ($N1, $N3) and set the traffic percentage that these traders will receive individually.

Step 1: P1, P2, P3 Calculation

This step must at least result in defining of $P1 - this variable represents trader's main points. You can additionally define $P2 and $P3 if you would like to take more factors into account. In order to calculate these values you can use 27 predefined trade characteristics (please see below). Actually, you'll have to write a short PHP code which will be used inside the cycle for each trader. Here's an example of such a code:

if($Dout>0) $P1=$Dclick/$Dout;
else $P1=0;

In fact, we have just defined the $P1 value for a trader, based on total number of clicks and outs from him during last 24 hours. This code is enough for a custom scheme to work, but if you want to take account of other trade characteristics, for example unique ins number or 'Click again' parameter, you can either complicate the formula for $P1 or create a new formula for $P2 or for $P3. All the formulas will be used simultaneously to conduct the trade, you will also set traffic volumes for each formula (please see Basic Notions). This results in a very high trading process flexibility: if you wish, you can only define the main formula for $P1 which will control the trade, otherwise you can define 2 formulas - $P1 and $P2 - trade will be conducted by these using defined probabilities, you can even set three formulas! Here's one more example:
if($Dout>0) $P1=$Dclick/$Dout;
else $P1=0;

$P2=$Dclick-$Duout;

if($Din>150) $P3=$P2*$Ca;
else $P3=$P2*$AverageCa;

if($Din==0){
    if($Duout>0) $P1=$P2=$P3=1/$Duout;
}
elseif($Duout/$Din)>=3) $P2=$P3=0;

Here, all three formulas are defined and new characteristics will be applied to a trade. Overflow protection is also added (more than x3 overflow).
You can complicate or simplify the code if you wish so. This feature will let you create the exact trading algorithm that you need.
I will now describe trade characteristics, variables and PHP functions which can be used to calculate points:

 

$DinNumber of raw ins from a trader during last 24 hours
$Hin Number of raw ins from a trader during the last hour
$Duin Number of unique ins from a trader during last 24 hours
$Huin Number of unique ins from a trader during the last hour
$Dout Number of raw outs from per trader during last 24 hours
$Hout Number of raw outs from per trader during the last hour
$Duout Number of unique raw outs from per trader during last 24 hours
$Huout Number of unique raw outs from per trader during the last hour
$Dclick Number of raw clicks from a trader during last 24
$Hclick Number of raw clicks from a trader during the last hour
$Duclick Number of unique clicks from a trader during last 24
$Huclick Number of unique clicks from a trader during the last hour
$Dproxyin Number of proxy ins from a trader during last 24 hours
$Hproxyin Number of proxy ins from a trader during the last hour
$Dproxyclick Number of proxy clicks from a trader during last 24 hours
$Hproxyclick Number of proxy clicks from a trader during the last hour
$Dtradeout Number of raw outs per trade from a given trader during last 24 hours
$Htradeout Number of raw outs per trade from a given trader during the last hour
$Hin_hours[0-23] * Array : Raw ins from a trader during n last hours (n is defined by you
$Hout_hours[0-23] * Array : Raw outs from a trader during n last hours (n is defined by you
$Hclick_hours[0-23] * Array : Raw clicks from a trader during n last hours (n is defined by you
$Huin_hours[0-23] * Array : Unique ins from a trader during n last hours (n is defined by you
$Huout_hours[0-23] * Array : Unique outs from a trader during n last hours (n is defined by you
$Huclick_hours[0-23] * Array : Unique clicks from a trader during n last hours (n is defined by you
$Ca ** Click Again value for a given trader
$AverageCa ** Click Again average value for the whole site
$Domain Trader's domain name
$Ratio Defined ratio for a trader (e.g. '130')
$MaxRatio Defined Max. Ratio for a trader (e.g. '200')
$Factor Defined Factor for a trader (e.g. '1.6')
$a Can be used at user's discretion
$b Can be used at user's discretion
$c Can be used at user's discretion
$d Can be used at user's discretion
$P1 Points P1. Must be defined!
$P2 Points P2
$P3 Points P3

Available PHP functions and operations:
 +, -, *, /, if, elseif, else, array_sum, count, round

Values marked with * and ** are available optionally in order to save server resources.

 * - These values are only available if 'Load expanded stats for the last' is set > 1, otherwise the array will be empty. For example:
Load expanded stats for the last 3 hours. Array $Hin_hours will contain 3 elements: $Hin_hours[0] - number of raw ins from a trader during the last hour (like $Hin)
$Hin_hours[1]
- number of raw ins from a trader during the following span of time : 2 - 1 hours before.
$Hin_hours[2]
- number of raw ins from a trader during the following span of time : 3 - 2 hours before. It works in a similar manner with other arrays. Maximum number of hours to view is 24, it means that you can get hourly stats for the past 24 hours.

** - These values are only available if 'Click again' stats needed is on.
IMPORTANT!

  • Variables are case-sensitive. Please use them exactly the same way as they are listed in the table. To copy a variable in the clipboard please click on its button - this is to make your life easier.
  • If you are using fractions, please make sure that the denominator is not equal to zero, or add 1 to the denominator to avoid having a zero divide.

Step 2: Creation of Points1, Points2, Points3

The second step is optional but it strongly affects your trade. When $P1 ($P2, $P3) are defined, the traders are sorted using these values. A total traders array $Points1 is created ($Points2 and $Points3 if $P2 and $P3 were defined). Now we'll have to pick the best traders from this array and put them in total outgoing lists. In order to define the number of traders in an outgoing list, use $N1, $N2 and $N3 variables. The second step code will only be executed once (and not in a cycle). A second step code example:

$N1=10;
$N2=5;
$N3=floor($active_trades_hour/2);

We have defined that the outgoing list for P1 will contain exactly 10 traders, the outgoing list for P2 - 5 traders and the outgoing list for P3 will contain half of the active traders during that hour.
But that's not all. If you just set the number of traders in an outgoing list, the final share of traffic received by a trader will be proportional to this trader's points. You can redefine this percentage manually (it's as if you were using 'Use custom rule for outgoing' and setting percentages in main out settings for all the trading schemes, please refer to the main manual for details) Here's an example:
 
$N1=10;
$N2=5;
$N3=floor($active_trades_hour/2);

$Points1=array();
$Points1[]=400;
$Points1[]=200;
$Points1[]=100;
$Points1[]=50;
$Points1[]=25;
$Points1[]=20;
$Points1[]=15;
$Points1[]=10;
$Points1[]=10;
$Points1[]=10;

$Points2=array();
$Points2[10]=2;
$Points2[9]=3;
for($a=8;$a>=0;--$a) $Points2[$a]=$Points2[$a+2]+$Points2[$a+1];

Here, the outgoing list for P1 is set permanently, traffic shares received by traders will be proportional to defined numbers (400, 200, 100, etc.). The numbers in the outgoing list for P2 are a Fibonacci series. Despite the fact that there are more elements in the array $Points2 than there should be ($N2), the outgoing list will only contain first 5 traders. If this array ($Points2) contained less elements than it should ($N2), the outgoing list would contain as many traders as there are elements in $Points2. The outgoing list for $P3 is not set at all. It means that the percentages will be proportional to points for each trader and the outgoing list will contain half of the active traders during that hour ($N3). If $N3 was not defined, the outgoing list for P3 would contain as many traders as it is defined in 'Number of trades in outgoing list' which is common for all trading schemes.
One more thing. If you want the values for an outgoing list to be similar to settings 'Use custom rule for outgoing' from main out settings, simply set $Points1='default'; (in fact, you can put anything in quotes). All right, I'll sum everything up using an example of an outgoing list for P1 (it will work the same way for other two outgoing lists):
  • If $N1 is not defined, then it will be equal to 'Number of trades in outgoing list' from main out settings.
  • If $Points1 is not defined, then it will be set equal to sorted points $P1 (that were calculated during the first step).
  • If $Points1 is defined as text, then it will be taken from settings 'Use custom rule for outgoing'
  • If $N1 is not equal to the number of $Points1 elements, the final outgoing list will contain a number of traders equal to the smallest of these values.

Here's the list of available variables and function for the second step :

$aCan be used at user's discretion
$b Can be used at user's discretion
$c Can be used at user's discretion
$d Can be used at user's discretion
$i Can be used at user's discretion
$Points1 Values array, the traffic will be given out proportionally to these values, sorted by $P1
$Points2 Values array --//-- $P2
$Points3 Values array --//-- $P3
$N1 Max traders number in $Points1
$N2 Max traders number in $Points2
$N3 Max traders number in $Points3
$active_trades_day Number of active traders during last 24 hours.
$active_trades_hour Number of active traders during the last hour.

Available PHP operations and functions:
+, -, *, /, if, elseif, else, array_sum, count, round, while, list, each, foreach, floor, array





Control
Imagine that you have created your own trading algorithm, defined your outgoing lists and saved the settings. How can you know whether this code is working and how these outgoing lists will look like?
First of all, code errors will be logged and written to this file : http://www.yourdomain.com/cron_error_log.txt If the code is written according to PHP rules and if you are only using allowed variables, there will be no errors.
Secondly, go to menu Settings -> Out Settings -> View your outgoing list here and you'll be able to see all of your outgoing lists with traders.

If you have invented an original trading algorithm but you can't realize it in Progress TM (you don't know PHP or didn't understand the manual) - I will be happy to help you. Please e-mail me at protontm@gmail.com and your message will be answered.